Open fabioaccetta opened 9 years ago
Moreover, if I comment those lines, my output has radio inputs always with empty values instead of their right own values. This strange behavior seems to happen in line 59:
var $template = $(widgetOptions.template);
Even if widgetOptions.template
(a text variable that contains html) has correct values in radio inputs, $template
has all of these fields with empty values.
In fact, if I continue in the same function with part of those commented rows:
$template.find('input[type="checkbox"], input[type="radio"]').each(function() {
var value = $(this).val();
alert(value);
});
I get always empty values instead of 'type1'
, 'type2'
, or 'type3'
.
I can't understand way...
The version considered in my previous post is the latest stable, while in the last master version this problem seems to be resolved (even if the radio is always prefilled with 1).
The problem still exists, because _fixFormValidaton
(row 298) fails trying to fix radio/check validation;
$(widgetOptionsRoot.widgetBody).find('input, textarea, select').each(function() {
var id = $(this).attr('id');
var name = $(this).attr('name');
if (id !== undefined && name !== undefined) {
[...]
In case of radio/checkbox list, last if
fails because the input generated by field()
method has no id
and the expected id is owned by the div
surrounding the radio/checkbox list.
@fabioaccetta good catch. I too facing same problem. Is is possible to generate id attribute for radio buttons?
For adding id attribute to the radio buttons I used below code.
<?= $form->field($client_allow_acces, "[$i]access_type")->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'],[ 'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
$custom_id = preg_replace("/[^a-zA-Z0-9]+/", "-", strtolower($name)).$value;
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" id="'.$custom_id.'" >';
$return .= '<span> ' . ucwords($label) . '</span>';
$return .= '</label>';
return $return;
}]); ?>
And also for fixing the radio buttons value issue I modified the package js file vendor/wbraganca/yii2-dynamicform/assets/yii2-dynamic-form.js on lines 74 and 77
$template.find('input[type="checkbox"], input[type="radio"]').each(function() {
var inputName = $(this).attr('name');
var inputID = '#'+$(this).attr('id'); //added newly
var $inputHidden = $template.find('input[type="hidden"][name="' + inputName + '"]').first();
if ($inputHidden) {
$(this).val($(inputID).val()); //modified
$inputHidden.val(0);
}
});
// $template.find('input, textarea, select').each(function() {
$template.find("input:not([type='radio'], [type='checkbox']), textarea, select").each(function() {
$(this).val('');
});
if ($inputHidden) {
// $(this).val(1);
$inputHidden.val(0);
}
This ?
@skySlec actually you are making static values. May I know what issue you are facing?
Has anyone found the solution for this problem, as i am currently facing the same and not sure what the solution is. I would like the radio list to use values that are provided in the array items but looks like widget is giving a static value of 1 to all of the items
<?= $form->field($carrierProfileVendor,"[{$index}]" . 'pulldata') ->radioList([ '1' => 'Yes', '0' => 'No', '-1' => 'On Hold' ])->label('Pulling Satellite Tracking Data:')?>
Instead of giving value = 0 to radio button 'No' it contains value of 1 and same goes for 'On Hold' radio button
Looking at row 72 of yii2-dynamic-form.js I see:
In my case
radio
inputs as textual values and not numerical ones, i.e.:In my case, those ones break my form, because the output I get is:
instead of
So, why those rows are necessary? Thanks