M
M
My joy2018-02-12 17:57:10
Yii
My joy, 2018-02-12 17:57:10

How to check the validation of an array of inputs?

There is a product form, and each product has a different price for different stores (bids). I create the form like this:

<? 
  $shops = Shops::find()->all();
  foreach($shops as $shop)
  {
    echo "<tr><td>{$shop->login}</td><td>" . $form->field($form, 'bids[' . $shop->id . ']')->textInput()->label(false) . "</td></tr>";
  }
?>

and in the model I check like this:
['bids', 'each', 'rule' => ['integer', 'min' => '0']],

And everything is fine, except that at the front, if you enter an incorrect value (for example, "-50"), then the validation does not pass, but visually the field is green (has-success), because The validator returns the following text:
{"form-bids":["Значение «Ставки» должно быть не меньше 0."]}

and accordingly, the yiiform handler cannot figure out which of the incorrect fields needs to be tinted.
How to solve the problem with input array validation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-12
@OKyJIucT

Do not allow negative numbers to be entered at the front, use regex to validate the data by the browser
Well, if the villain still bypassed this - highlight the entire block of inputs, and not a specific one with an error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question