sebastienheyd / boilerplate

Laravel AdminLTE 3 Boilerplate package with blade components, users, roles and permissions management
MIT License
221 stars 66 forks source link

Validation issue #59

Closed cod3rshotout closed 2 years ago

cod3rshotout commented 2 years ago

I'm trying to set a conditional validation which must check this:

So in my blade view:

@if ($riskfield->type == 'min_max')
<x-boilerplate::input type="number" name="values[min]" label="medicalrecords.min" required
    placeholder="medicalrecords.min_plc" autofocus="true" min="0" prepend-text="fas fa-signature">
</x-boilerplate::input>

<x-boilerplate::input type="number" name="values[max]" label="medicalrecords.max"
    placeholder="medicalrecords.max_plc" autofocus="true" min="0" prepend-text="fas fa-signature">
</x-boilerplate::input>
@elseif($riskfield->type == 'number')
<x-boilerplate::input type="number" name="values[number]" label="medicalrecords.number" required
    placeholder="medicalrecords.number_plc" autofocus="true" min="0"
    prepend-text="fas fa-signature">
</x-boilerplate::input>
@endif

and also at the top of my form I have an hidden field:

<input type="hidden" name="riskfield_type" value="{{ $riskfield->type }}">

Then in the store method there is this validation config:

   $this->validate($request, [
        'riskfield_id'      => 'required',
        'riskarea_id'       => 'required',
        'values[min]'       => 'required_if:riskfield_type,==,min_max',
        'values[max]'       => 'required_if:riskfield_type,==,min_max',
        'values[number]'    => 'required_if:riskfield_type,==,number'
    ]);

Now the problem's that if I fill both values[min] and values[max] I get:

The values [min] field is required when the riskfield type is min_max.

So I changed the validation as:

'values.min'        => 'required_if:riskfield_type,==,min_max',
'values.max'        => 'required_if:riskfield_type,==,min_max',

and this fix the problem but the error message doesn't appear because it contains:

{"values.max":["The values.max \u00e8 is required when the riskfield type \u00e8 min_max."]}

and within input.blade.php we have:

$errors->first($name,' is-invalid')

So I suspect that this condition fails