vendredi 3 février 2017

Laravel Form:checkbox: how to add multiple attributes after ternary operator

I am using the Form:checkbox helper function. I dynamically compare database data and disable the checkbox by adding the attribute disabled. This works.

Form::checkbox(
                       'prog_bookings['. $attendee->id .']['. $program->id .']',
                       'on',
                       $registered = ($attendee_registered = $program->attendees->find($attendee))? $attendee_registered->pivot->registered: 0,

                       array('data-cascade' => 'reg' . $attendee->id . '-' . $program->id,
                             'class'        => 'checkbox validate ',
/*here is my ternary op*/    (($attendee->age >= $program->min_age) && ($attendee->age <= $program->max_age) ?
                                  null :
                                  'disabled'
                               )
                       )
)

Now, in addition to the disabled attributte I want to add attributes to create an addtional tooltip

Form::checkbox(
                       'prog_bookings['. $attendee->id .']['. $program->id .']',
                       'on',
                       $registered = ($attendee_registered = $program->attendees->find($attendee))? $attendee_registered->pivot->registered: 0,

                       array('data-cascade' => 'reg' . $attendee->id . '-' . $program->id,
                             'class'        => 'checkbox validate ',
/*here is my ternary op*/    (($attendee->age >= $program->min_age) && ($attendee->age <= $program->max_age) ?
                                  null :
/*added more here -->*/           ('disabled', 'data-toggle'=>'tooltip', 'title'=>'age not met','data-container'=>'body') 
                               )
                       )
)

This results in an error unexpected ',' I suspect that is from the ',' following disabled.

Did I mess up the usage? Is there a workaround using php? I would like to keep the code on the server and not use js call to change it after.




Aucun commentaire:

Enregistrer un commentaire