In laravel 5 how do i validate an array to check if at least one value is selected - the following doesn't work?
'user_list[]' => 'array|min:1',
{{ Form::select('user_list[]', $users, null , ['multiple' => 'multiple']) }}
fixed by changing the field name in the rules array as follows and by adding a required rule:
'user_list' => 'required|array|min:1',
{{ Form::select('user_list[]', $users, null , ['multiple' => 'multiple']) }}
Related
I have x-editable form with two fields editable-text and editable-number.
%form{"editable-form" => "", :name => "editableForm", :onaftersave => "savePaymentDetails()"}
%table.table.table-striped
%tr{"ng-repeat" => "obj in bussiness_info.text"}
%td
%h6.blue
{{ obj.name | camelize}}
%td{"ng-if" =>"obj.type=='text'"}
%span{"e-name" => "obj.name", "e-ng-required" => "obj.required", "editable-text" => "obj.value"} {{ obj.value || 'empty' }}
%td(ng-if="obj.type=='number'")
%span{"e-name" => "obj.name", "editable-number" => "obj.value", "e-ng-required" => "obj.required","e-step" => "0.01","e-max"=>100} {{ obj.value || 'empty' }}
So,on clicking edit the form should populate both editable-text and editable-number fields if its values are present already.In my case both the fields the has the value,but only the editable-text alone is populated.
The editable-number is not getting populated with the pre-present value.I am not sure whether this because of any scope issues or something else.
I figured it out. Its my blunder. The typeof both tin_no(editable-text field) and margin(editable-number field) were String.So my editable-number field was not getting populated. Editable-number field got populated after changing the type of margin to Number.
Im new to twig and having a hard time getting what I need out of an array.
Here is my output from
{{ dump(items) }}
array (size=1)
0 =>
array (size=2)
'content' =>
array (size=4)
'#type' => string 'processed_text' (length=14)
'#text' => string '8AS09DF8a90sd80' (length=15)
'#format' => string 'basic_html' (length=10)
'#langcode' => string 'en' (length=2)
'attributes' =>
object(Drupal\Core\Template\Attribute)[2249]
protected 'storage' =>
array (size=0)
...
So I have an object(i think) with nested info inside of it
I am trying to pull out the '#text' of 8AS09DF8a90sd80 but cant get anything but the dump to work.
Ive tried:
{{ dump(items[0]) }}
{{ dump(items['content']) }}
{{ items.content }}
{{ items.['content']['text'] }}
and a bunch of other formats, nothing works!!
How do I structure this in twig?
This should work:
{{ items.0.content['#langcode'] }}
We need to use:
0 to select the first key of the items array
content to select the content node
#langcode to get the value with #langcode key
Where . and [] have the same role: they are used to access to an attribute of an object, in this case the value associated to a key in an array. But writing items.0.content.#langcode would trigger a syntax error because # is not a valid character (1), so we have to use the other syntax ['#langcode'].
Source: Official documentation.
(1): I didn't tested but I'm pretty sure of this.
I'm editing a dropdown box. i need to use empty and selected in same dropdown.
here is my code
$this->Form->input('per', array('id'=>'per','class'=>'inputs con_field','label'=>'per :', 'type'=>'select','options'=>$per_values,'selected'=>$labrcfps['Labourcfps']['per'],'empty'=>'- - Select --'));
If i use empty it automatically takes the empty as selected value.
I'm new in cakephp but i do this with array and parameter defaults :)
like that:
$options = array(
'x' => 'Select',
1 => 'Something',
2 => 'Car',
3 => 'Train'
);
echo $this->Form->input('name', array(
'options' => $options,
'default' => 'x'
));
Maybe that will be working fine :)
Variable $options is just your options after that you can validate if name of that field has value integer or 'x'. If 'x' then deny rest of logical code
I have a form and i have ended it using,
echo $this->Form->end('Login');
However, i can't seem to assign it an id or class to style it and be able to reference it with jquery. Also,I want to style it with a picture and the picture has the text already in so i need the buttons value to be empty but i can't manage that either...
Any Help?
Many Thanks, Chris
***Note - this is the html it generates;
<div class="submit"><input type="submit" value="Login"/></div>
Ideally i would like to remove the div aswell but its not a necessity.
here's the solution:
$options = array
(
'label' => 'Update',
'value' => 'Update!',
'id' => 'blabla',
'div' => array(
'class' => 'glass-pill',
)
);
echo $this->Form->end($options);
Cheers! =)
I have a selectbox like this
$form->select('city_id',$city, array ('empty'=>false, 'selected'=>'1',
'label'=> false), array('label'=>false, 'div'=>false, 'name'=>'city_id',
'id'=>'city_id'));
I need to remove the empty option at the top of my options. I even set the
''empty'=>false' but it not works!!!
Can anyone help me please
It looks like you've messed up your arguments to $form->select().
The 1st is the field name, the 2nd is an array of key/values of select options for the user to pick from, 3rd argument should be the selected element value (or null) and the 4th the array of options, which is where you can include 'empty' => false.
select(string $fieldName, array $options, mixed $selected, array $attributes)
See the select documentation in the CakePHP Cookbook.
<?php echo $this->Form->input('foo.bar', array('type' => 'select', 'options' => array(1 => 'foo', 2 => 'bar'), 'empty' => false)); ?>
Works for me..