I work with symfony framework and I have two select Type:
the 2nd select is initially Hidden and relative to the value of the first select the 2nd select will be displayed : for that I tried to do $this :
Script
<script type="text/javascript">
$(document).ready(function () {
$('.type-produit ').change(function() {
if ($('select[id$="_type"]>option:selected').text() == "Unité")
{ $('.hidden ').show(); }
});
});
</script>
FormType
$formMapper
->add('type','choice', array(
'choices' => array('Kg' => 'Kg', 'Unité' => 'Unité'),
'label' => 'Type de vente',
'attr' =>array('class'=>'type-produit')
))
->add('soustype',HiddenType::class, array(
'data' => ['Liquide'=>'Liquide','Autres'=>'Autres'],
'label' => 'Sous types',
'attr'=>array('class'=>'hidden')
))
But the 2nd select still not displayed , someone can help me please ? thanks for all
Change the soustype field to choice type (HiddenType field is rendered as <input type="hidden">), then you can hide or show the field in the script.
FormType
...
->add('soustype', 'choice', array(
'choices' => ['Liquide'=>'Liquide','Autres'=>'Autres'],
'label' => 'Sous types',
'attr' => array('class'=>'soustype')
))
Script
$(document).ready(function () {
$('.soustype').hide();
$('.type-produit ').change(function() {
if ($('select[id$="_type"]>option:selected').text() == "Unité") {
$('.soustype ').show();
}
});
});
Related
I have two select2 options
I want to implement something like, if user click daily they can use the Select2 option of Days, But if they select Monthly then the another Select2 button will be disable. Can u check why my code isn't working.
{{ Form::select('type', $type, null, ['class' => 'form-control select2', 'onchange' => 'myFunction()', 'id' => 'recurring_type', 'required' => 'true', }}
{{ Form::select('days', $days, null, ['class' => 'form-control select2', 'id' => 'days', 'required' => 'true', }}
And this is the javascript
function myFunction() {
if($(this).val() === 'Daily') {
$('#days').select2('disable');
} else {
$('#days').select2('disable');
}
}
My blind guess is that $(this).val() is not equal to "Daily". You definatelly should recheck what you get with console.log($(this).val()) in beginning of myFunction
im trying to display an input according to the value of a drop-down list with symfony
my select box
->add('specialite', ChoiceType::class, [
'attr' => ['class' => 'form-control mb-3'],
'label' => 'Speciality',
'choices' => array(
'Select' => null,
'Nurses' => 'nurses',
'Doctors' => 'Doctors',
'Engineers' => 'Engineers',
'IT-Specialist' => 'IT-Specialist',
'Anesthetist technicians' => 'Anesthetist technicians',
'Others' => 'Others',
),
'choice_attr' => [
'Select' => ['disabled'=>'disabled'],
]
])
when the user select others , another field it displayed to him , im trying also with this code
form type
->add('otherspec', TextType::class, [
'attr' => ['class' => 'form-control mb-3'],
'label' => null,
])
html.twig
<script>
let foo = document.getElementById("emplopyer_specialite");
let bar = document.getElementById("emplopyer_otherspec");
foo.addEventListener('change', (event) => {
if (event.target.value === 'Others') {
bar.style.display = 'none'; // Hide the element.
} else {
bar.style.display = 'inline'; // Show the element.
}
});
</script>
My problem
my problem is whene i select any value of the select box , the second field appear , however i want it appear when i select the value="other"
thanks
If you console.log your event.target.value, you can see '1', '2'...
The offender is : 'Select' => null
Documentations says :
If there are choice values that are not scalar or the stringified representation is not unique Symfony will use incrementing integers as values. When the form gets submitted the correct values with the correct types will be assigned to the model.
So, if you want string as value, you have to set string in your Select key.
Or you can change your js condition with 6.
I want to add 21 checkboxes and a text field(Name) in a good design way. Also there must be "check all button" to check all the checkboxes, how to do it in module PHP page in prestashop.
Since I am new to prestashop I don't know about the form submission, I have to save these two fields together as a json array in database.
Is that possible in prestashop? please help me regarding this.
prestashop version = 1.6
Thanks in advance
Sample code
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l( 'Generate Export Order Settings' ),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'checkbox',
'name' => 'display',
'values' => array(
'query' => array(
array(
'id' => 'all_fields',
'name' => $this->l('All Fields'),
'val' => '1'
),
),
'id' => 'id',
'name' => 'name'
)
),
),
'submit' => array(
'title' => $this->l( 'Save Export Settings' ),
'class' => 'button pull-right',
'name' => 'save-main-display-settings',
)
),
);
}
I don't know how to add check box in 3 columns and 7 rows and select all button to select all the checkbox.
You can use the following JS code to add check all functionality:
$('.chk_boxes').click(function(){
var chk = $(this).attr('checked')?true:false;
$('.chk_boxes1').attr('checked',chk);
});
Fiddle here: http://jsfiddle.net/HBGzy/
I'm trying to put a value from javascript into a form action in Yii2
is it possible?
More specifically I need to make a URL change for each option that is selected in a dropdownList.
form in views/site.php
$form = ActiveForm::begin([
'id' => 'form',
'method' => 'POST',
'action' => Url::to(['programas/'.Tours::findOne(['pk' => ])->programa]),
]);
<?= $form->field(new \app\models\Tours(), 'nombre')->dropDownList([],
[
'prompt' => 'Programa',
'id' => 'child1_child2',
'onchange' => 'updateValue(this.value)',
]
)->label(false); ?>
Js file
function updateValue(val){
x = document.getElementById("test").value;
// document.getElementById("form").action = "programas/";
}
So, I rescue the value from the selected option with JS but I need to put it in here 'pk' => 'value'
where value is the #child1_child2 selected option value.
'action' => Url::to(['programas/'.Tours::findOne(['pk' => ])->programa])
Thanks for the help.
You can use one of the following approach with some modification:
//pk => programa
$data = [
1 => 'programa1',
2 => 'programa2',
3 => 'programa3',
];
1) Use JS
<?= $form->field(new \app\models\Tours(), 'nombre')->dropDownList($data, ['prompt' => 'Programa'])->label(false); ?>
JS
$this->registerJs('
$("#dropdownID").change(function() {
var text = $("#dropdownID option:selected").text();
$("#formID").attr("action", "/pathtoproject/programas/" + text);
});
', \yii\web\View::POS_END);
2) Use Ajax Call
<?= $form->field(new \app\models\Tours(), 'nombre')->dropDownList($data, [
'prompt' => 'Programa',
'onchange'=> '$.get( "'.Url::toRoute('get-action').'", { id: $(this).val() } )
.done(function( data ) {
$("#formID").attr("action", data);
}
);'
])->label(false); ?>
Controller
public function actionGetAction($id)
{
$name = Tours::findOne(['pk' => $id])->programa];
echo \yii\helpers\Url::to(['programas/'.$name]);
}
I'm trying to add custom tag to cakephp form input but it won't apply.
I am using Bootstrap switch
My code :
$this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'data-label-text' => $items,
'class' => 'form-control',
));
att: i want to add item names as a 'data-label-text'
this is working (with out other attributes)
$this->Form->checkbox('aaa', array('data-label-text'=>'new item out'));
Any idea ? help ?
Try this
$options = array(0 => 'new item out 1', 1 => 'new item out 2');
echo $this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'options' => $options,
'class' => 'form-control',
));