outl1ne/nova-simple-repeatable

[2.2.0] Deleting a row leaves rows with a different row index than what is being submitted

dmason30 opened this issue · 4 comments

SimpleRepeatable::make('Charges', 'charges',[
  Currency::make('Limit', 'limit')->rules(['required', 'integer', 'min:1', 'distinct'])->step(1),
  Currency::make('Charge', 'charge')->rules(['nullable', 'numeric']),
]),

Steps:

  1. With the above field on a form add 3 rows you will end up with inputs with correct indexes 0,1,2
  2. Submit the form with empty fields and you will get The charges.x.limit field is required on all 3 rows. This is expected.
image
{
    "message": "The charges.0.limit field is required. (and 2 more errors)",
    "errors": {
        "charges.0.limit": [
            "The charges.0.limit field is required."
        ],
        "charges.1.limit": [
            "The charges.1.limit field is required."
        ],
        "charges.2.limit": [
            "The charges.2.limit field is required."
        ]
    }
}
  1. Delete the first row

  2. Submit the form again with empty fields, only the first row shows The charges.1.limit field is required

image
{
    "message": "The charges.0.limit field is required. (and 1 more error)",
    "errors": {
        "charges.0.limit": [
            "The charges.0.limit field is required."
        ],
        "charges.1.limit": [
            "The charges.1.limit field is required."
        ]
    }
}

This is because the two rows have indexes 1 and 2 but the data being submitted for validation has indexes 0 and 1.

Thank you for report. This will be fixed in the next release.

Released in 2.2.1. Good luck!

@marttinnotta @Tarpsvo Could you reopen this, since the fix was reverted?

Thank you for the report!

We had some issues with the update that would send data in FormData format and this was also reverted thanks to that. Will look into it.