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
Related
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 display a value in a drop-down whenever I edit content, but I don't know how can I show it. Can someone help me with this?
Dropdown
Here I have a dropdown that has the value of the country when I insert it to the database. But when I edit the drop-down, the country saved will be removed.
{{ Form::select('from_location', trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select where you From']) }}
Update Controller
$aircraftFlights = Aircraft::find($id);
$aircraftFlights ->destination= $request->input('destination');
$aircraftFlights ->save();
You are passing null into field for current value.
Try this:
{{Form::select('from_location', trans('countries'), !empty($aircraftFlights) ? $aircraftFlights->destination : null ,['class' => 'form-control', 'placeholder' => 'Select where you From'])}}<br>
You can refer here for more details:
https://laravelcollective.com/docs/5.4/html#drop-down-lists
{{Form::select('from_location', trans('countries'),null,['class' => 'form-control', 'placeholder' => 'Select where you From', 'value' => $your_value_here])}}
I've seen many topics about questions like mine, but I can't get any solutions.
I'm using Symfony, and I have a twig template which displays a form.
Imagine that I have this line :
{{ form_row(demandeForm.distinction) }}
Thanks to this :
->add('distinction',null, [
'label_attr' => array('id' => "distinct_form"),
'required' => false,
'label' => 'distinction'
])
I also have a submit button. My wish is to modify the value of my row "distinction" when the button is clicked (id of the submit button : formDepot).
Here is my code :
$(document).ready(function(){
$('#formDepot').click(function(){
$('#distinct_form').value('555');
});
});
When I retrieve my datas on submit, I don't have any value in my "distinction".
Any ideas ?
Thanks
This is because you're applying the changes on the label value, not on the input itself.
'label_attr' => array('id' => "distinct_form") and in js : $('#distinct_form').val('555');
Change the form builder to this :
->add('distinction',
null,
[
'attr' => array('id' => "distinct_form"),
'required' => false,
'label' => 'distinction'
])
With attr for the field (not the label), you can try
$('#distinct_form').val('555'); not .value();
You are assigning a value, instead of getting the value, try this .....
$(document).ready(function(){
$('#formDepot').click(function(){
$('#distinct_form').val();
});
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();
}
});
});
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',
));