jeudi 6 décembre 2018

Select input with 2 empty option values

In my laravel 5.7/mysql 5 app I have boolean is_quiz field in my vote Table and in model I define:

protected $casts = [
    'is_quiz' => 'boolean',
];
...

And array with possible values/keys for using of this fields

private static $voteIsQuizLabelValueArray = Array(1 => 'Is Quiz', 0 => 'Is Not Quiz');

in control I add empty value for empty selector:

$viewParamsArray['voteIsQuizValueArray']         = $this->SetArrayHeader(['' => ' -Select Is Quiz- '], Vote::getVoteIsQuizValueArray(false));

and this array has values:

$viewParamsArray['voteIsQuizValueArray']::Array
(
    [] =>  -Select Is Quiz- 
    [1] => Is Quiz
    [0] => Is Not Quiz
)

In my form this array as :



and in rendered html-source I see 2 options selected :

<select id="is_quiz" class="form-control editable_field select_input valid" name="is_quiz" aria-invalid="false" aria-describedby="is_quiz-error"><option value="" selected="selected"> -Select Is Quiz- </option><option value="1">Is Quiz</option><option value="0" selected="">Is Not Quiz</option></select>

and validator.w3.org raised error here. I see what is the reson of the syntax error, but I do not know is there is easy way to fix it ?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire