CakePHP3 Multi Checkbox custom attribute - cakephp-3.0

I am using the the Cake
<?= $this->Form->input('vehicles._ids', ['label' => 'Vehicle', 'options' => $vehicles, 'multiple' => 'checkbox', 'ng-model' => 'vehicles']); ?>
For each check box I want to add the custom attributes: 'ng-model'
I can see that the generation of multiple checkboxes is handled by the class file MultiCheckboxwidget.php and checkboxes use the 'checkbox' template:
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
But since by default this uses {{attrs}} I can't see why my custom ng-model attribute isn't being added to the generatred form input. Instead this is the amrk-up crearted by the helper:
<input type="checkbox" name="vehicles[_ids][]" value="1"id="vehicles-ids-1" class="ng-valid">
How can I add ng-model to each of the checkbox inputs?

Upgrading my verison of CakePHP form 3.3.12 to 3.4 resolved the issue, the formhelper must have been refined in the latter versions.

Related

ExportMenu Kartik doesn't work in yii2 GridView widget

The export dropdown and toggle dropdown do not appear on click. I can't see any errors in console of developer tool.
I have used exactly same code in another project and that seems to work, the only difference is in the column set.
<?php
$exportColumns=[
'name',
'email',
'username',
];
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' =>$exportColumns,
'dropdownOptions' => [
'label' => 'Export All',
'class' => 'btn btn-secondary'
]
]);
?>
I had a similar issue with my own Yii2 project. In my project the dropdown menu worked, but the buttons that appeared were unresponsive and the entire page froze without any console error.
My own mistake was that I required two bootstrap versions in my composer.json (I left in yiisoft/yii2-bootstrap in my case, removed the other).
Double Bootstrap

yii2 star widget does not appear

I can not see starwidget in my yii2, I installed the widget, but it doesn't display stars.
See loading gif:
Following is my code:
echo '<label class="control-label">Rating</label>';
echo StarRating::widget([
'name' => 'rating_2',
'value' => 2.5,
'disabled' => true
]);
Is there an explanation to this. Please help!?
Check your js assets. Check if jQuery is not loading twice.

yii2 AutoComplete position

It was working perfectly, I have changed nothing, and I have realized that my AutoComplete widget is showing up not there where it was before (it was in the gridView, right underneath the filter textinput where it is expected). Now it shows up in the left upper corner of the page, with the first 2-3 options covered by the navbar. Is there a change in AutoComplete, or in Yii2 now? I have found an option appendTo that has maybe something to do with the problem, and I have done experiments with it but no luck, either it doesn't show up, or still on the wrong place. I have found nothing else relevant.
Here is my code in the gridview:
[
'attribute' => 'name',
'contentOptions' => ['nowrap' => 'nowrap'],
'filter' => AutoComplete::widget([
'model' => $searchModel,
'attribute' => 'name',
'clientOptions' => [
'source' => Pl::find()->allAutoCompleteName(),
'autoFill' => true,
],
'options' => ['class' => 'form-control']
]),
],
The id of the search field is plsearch-name
The js:
jQuery('#plsearch-name').autocomplete({"source":[{"value":"PE 150","label":"PE 150"}...],"autoFill":true});
If I'm setting the appendTo in clientOptions to '#plsearch-name', then it doesn't show up at all, however it is correct, isn't it? I don't see any styling in it.
What also quite interesting is:
<input
type="text"
id="plsearch-name"
class="form-control ui-autocomplete-input"
name="PlSearch[name]"
autocomplete="off"/>
What is this autocomplete="off" doing there?
Can you please point me to the right direction? Thanks a lot!
This Problem is fixed here: https://github.com/yiisoft/yii2-jui/commit/36468550d72bce9d963149abe85b13ea2f3a8c18
The JQuery UI Version should be updated to 1.12
"require": {
"yiisoft/yii2": "~2.0.4",
- "bower-asset/jquery-ui": "1.11.*#stable"
+ "bower-asset/jquery-ui": "~1.12.1"
},

yii2 inserting a value, when 'other' option is choosen, in dropdown list

I have a dropdown list in my form, and I would like to enable the user to an option of 'other', which would enable him to insert a value in to a text box, instead of a value from the dropdownlist.
Is that possible?
<?= $form->field($model, 'institution')->dropDownList(ArrayHelper::map(Institution::find()->all(), 'iId', 'name'), ['class'=>'form-control inline-block']); ?>
The same thing I would like to do with a radioList.
<?= $form->field($model, 'selfDescription')->radioList(array('good'=>'good','very good'=>'very good','best'=>'best')); ?>
thanks.
First. Add "other" option to dropDownList. And handle it in your frontend with JS
$form
->field($model, 'institution')
->dropDownList(
ArrayHelper::map(Institution::find()->all(),
'iId',
'name'
) + ['other' => 'Other'],
[
'class'=>'form-control inline-block',
// next code disables text field when any but "other" option is selected
// works for jQuery 1.6+
'onchange' => new JsExpression('
$("#textFieldSelector").prop("disabled", $(this).find("option:selected").val() != "other");'),
]
);
Then you need to set properly your validators. Just add
['textField', 'required', 'when' => function($model) {
return $model->institution === 'other';
}]

Radio button needs to be reset while refreshing

I am having two radio buttons namely users and groups.
If is select groups and refresh the browser it stays in groups itself.
When i give ctrl+f5 it's getting reset to users.
My need is:
While i click the refresh button in browser the radio button should be reset to users even it is selected as groups.
EDIT : CODE
$form['groups'] = array(
'#title' => t('Groups'),
'#type' => 'select',
'#multiple' => 3,
'#options' => $options,
);
$form['users'] = array(
'#type' => 'textfield',
'#title' => t('Users'),
'#description' => t('Separate multiple names with commas.'),
'#default_value' => '',
);
This is task developing using drupal and jquery..
Any help regarding this will be grateful and thankful...
Thanks in advance...
You can try this:
<html>
<head>
</head>
<body onload="clearItForm.reset();">
<form name="clearItForm">
<input type="radio" name="sweets">Ice Cream<br>
<input type="radio" name="sweets">Candy Bars<br>
<input type="radio" name="sweets">Milk Shakes<br>
</form>
</body>
</html>
An alternative to Robby Shaw's good answer is to reset the form outside of the html, in some JavaScript.
window.onload = function(){
clearItForm.reset();
}