1

This is my form checkboxList with arrayhalper:

<div class="form-group">
    <?= $form->field($model, 'reg_id')->checkboxList(
        arrayHelper::Map(Riders::find()->where(['user_id' => Yii::$app->user->identity->id])->all(),'rider_id',
            function($model) { return **$model->rider_firstname . " (" . $model->cagoriesCategory->category_name . ")"**; }),
        ['class' => 'checkbox-inline', 'id' => 'person' ]), ?>
</div>

The label its work correctly, example: Jilly (MasterA). But I want to get value difference with label, example like this Jilly:MasterA. How to give values like this?

2
  • I don't understand what do you need. Please explain better ... Commented Nov 6, 2015 at 17:50
  • Sorry for bad language. simple example like this <input type="checkbox" id="person" value="Ristha:MasterA">Ristha (MasterA)</input> @scaisEdge Commented Nov 7, 2015 at 2:49

2 Answers 2

1

You need to change array value syntax. like as,

<div class="form-group">
    <?= $form->field($model, 'reg_id')->checkboxList(
        arrayHelper::Map(Riders::find()->where(['user_id' => Yii::$app->user->identity->id])->all(), function($model) { return $model->rider_firstname . " : " . $model->cagoriesCategory->category_name; },
            function($model) { return $model->rider_firstname . " (" . $model->cagoriesCategory->category_name . ")"; }),
        ['class' => 'checkbox-inline', 'id' => 'checkbox' ]); ?>
</div>
Sign up to request clarification or add additional context in comments.

6 Comments

thank, i want get value like this because can make me easily get split to show on table
sorry, When i use simple example in above its work correctly when i show use alert $('#idOfButton').click(function(){ $('[id="person"]:checked').each(function(){ var arr = $(this).val(); alert(arr); }); }); but when i use arrayhelper like that its not work. @GAMITG
Above example works fine with arrayHelper on my localhost.
its not shown my alert when i use arrayHelper T.T @GAMITG
I will check than say you.
|
1

Its work what i want, thank to @GAMITG

<div class="form-group">
    <?= $form->field($model, 'reg_id')->checkboxList( 
    arrayHelper::Map(Riders::find()->where(['user_id' => Yii::$app->user->identity->id])->all(), function($model) { return $model->rider_firstname . ":" . $model->cagoriesCategory->category_name; }, 
        function($model) { return $model->rider_firstname . " (" . $model->cagoriesCategory->category_name . ")"; }), 
    ['item' => function($index, $label, $name, $checked, $value) { 
        $return = '<label>'; 
        $return .= '<input type="checkbox" name="' . $name . '" value="' . $value . '" class="checkbox-inline" id="person1">';
        $return .= '<span>' . ucwords($label) . '</span>'; 
        $return .= '</label>'; 
        return $return; 
    } ]); ?>
</div>

then javascript code to cek it:

$('[id="person1"]:checked').each(function() {
    var arr = $(this).val();
    alert(arr);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.