How to give a validation on if condition like in my project case there are two inputs one is deal type and one is event name .so i have to give a condition like if deal type is single then i have to validate that event name otherwise no.
Here is my view :
<select name="deal_type">
<option value="">--Select--</option>
<option value="annual">Annual</option>
<option value="single">Single</option>
</select>
<select name="eventname">
<option value="">--Select--</option>
<option value="event1">Event1</option>
<option value="event2">event2</option>
</select>
my validation request.php :
public function rules()
{
return [
'deal_type'=>'required',
'eventname'=>'required_if:deal_type,single'
];
}
I was trying something like above but it is not working .Any suggestions please.
Related
I have a express server that passes in information from a mongo db into a ejs file. I am trying to update an item in the db. I want to have the current item information entered in as placeholders.
Here is the ejs code I'm not sure how to select one option based on the info from the db.
<select name="category" id="Category" placeholder="<%= product.category %>">
<option value="vegetable">Vegetable</option>
<option value="fruit">Fruit</option>
<option value="dairy">Dairy</option>
</select>
I understand that to have an option as the placeholder you generally have to use <option selected>
Any suggestions are much appreciated.
Use a Ternary Operator
<select name="category" id="Category">
<option value="vegetable" <%=product.category==='vegetable' ? 'selected' : '' %>>Vegetable</option>
<option value="fruit" <%=product.category==='fruit' ? 'selected' : '' %>>Fruit</option>
<option value="dairy" <%=product.category==='dairy' ? 'selected' : '' %>>Dairy</option>
</select>
I use reactive forms within my app. In a certain form I want to display a required (Validators.required) select like this:
<select class="form-control"
[id]="dformControl.key"
[formControlName]="dformControl.key"
[multiple]="dformControl.multiple">
<option *ngIf="!dformControl.value"
value="undefined">
Choose ...
</option>
<option *ngFor="let opt of dformControl.options"
[value]="opt.value"
[selected]="dformControl.value == opt.value">
{{opt.label}}
</option>
</select>
The problem is whether I use value="undefined" or value="" the form control still is set to valid because it got a value. Do not present the value attribute results in value="Choose ...".
Am I using select with reactive forms in a false way or how would I be able to make the option "Choose ..." being not valid??
Assigning initial value of select control to null will do the trick. Try below,
model_property = null
....
this.fb.group({
....
'control_key' : [this.model_property, Validators.required]
...
})
Check this Plunker!!, Look into app/reactive/hero-form-reactive.component.ts file.
I updated the Plunker to include below and it seems to be working,
<select id="power" class="form-control"
formControlName="power" required >
// see the value is set to empty,
<option value="">Choose...</option>
<option *ngFor="let p of powers" [value]="p">{{p}}</option>
</select>
Hope this helps!!
What I do is add a blank option and when that is selected since there is no value it is not valid.
<select class="form-control"
[id]="dformControl.key"
[formControlName]="dformControl.key"
[multiple]="dformControl.multiple">
<option></option>
<option *ngFor="let opt of dformControl.options"
[value]="opt.value"
[selected]="dformControl.value == opt.value">
{{opt.label}}
</option>
</select>
I am writin a macro excel to fill out a form in a web site.
My issue is that I can valorize the drop down menĂ¹ (is a select command) but this should activate and populate a second drop down menĂ¹.. that does not appear
The code is
' this is the first select to choice the REGION
<select name="ctl00$cp$ddlRegion" id="ctl00_cp_ddlRegion">
<option value="">seleziona...</option>
<option value="13">Abruzzo</option>
<option value="17">Basilicata</option>
<option value="18">Calabria</option>
<option value="15">Campania</option>
<option value="08">Emilia-Romagna</option>
<option value="06">Friuli-Venezia Giulia</option>
<option value="12">Lazio</option>
<option value="07">Liguria</option>
<option value="03">Lombardia</option>
</select>
'the second select, depending from the region above, valorize the CITY
<select name="ctl00$cp$ddlProvince" id="ctl00_cp_ddlProvince">
<option value="">seleziona...</option>
<option value="070">Campobasso</option>
<option value="094">Isernia</option>
</select>
MY CODE IS:
IE.document.ALL("ctl00$cp$ddlRegion").Value = "03" ' that is LOMBARDIA
but after this line the value it appear.. but the second select does not activate.
I have tried with
IE.document.ALL("ctl00$cp$ddlRegion").focus
IE.document.ALL("ctl00$cp$ddlRegion").click
IE.document.ALL("ctl00$cp$ddlRegion").fireEvent ("onchange")
IE.document.ALL("ctl00$cp$ddlProvince").focus
IE.document.ALL("ctl00$cp$ddlProvince").disabled = false
BUT NOTHING... does anybody knows why......
thank you in advance
Alex
Im a bit of a jQuery novice.
I have 5 options in a drop down menu.
I want to add a class in a div depending on which option is selected.
This class will then change the layout of the content using CSS.
Here is an example if it helps!
Thanks
<form>
<select>
<option id="1">layout 1</option>
<option id="2">layout 2</option>
<option id="3" selected>layout 3</option>
<option id="4">layout 4</option>
<option id="5">layout 5</option>
</select>
<div class="3">styled content</div>
</form>
You can use the ".attr()" to set the class attribute of the div onchange.
You're best to change the option id to value first. then:
$("select").change(function() {
$("div").attr("class", $(this).val());
});
(EDIT) Change it to:
$("select#np_blog_layout").change(function() {
$("div#changebox").attr("class", $(this).val());
});
What 'rudeovski ze bear' said, but if you still want to set it to the div's class to the selected elements id, here it is.
$('select').change(function() {
$('div').attr('class', $(this).attr('id'));
});
First off, you don't have to use id to your options. Put the values in value attribute. Put ID to your div and select so you can select them using jQuery.
<form>
<select Id="selectElement">
<option value="1">layout 1</option>
<option value="2">layout 2</option>
<option value="3" selected>layout 3</option>
<option value="4">layout 4</option>
<option value="5">layout 5</option>
</select>
<div id="styledContent" class="3">styled content</div>
</form>
On JS
//Attach event handler to select element's onchange event
$('#SelectElement').bind("change",changeStyle);
//The event handler
function changeStyle()
{
//Set class to selected value
$('#styledContent').class($('#SelectElement').val());
}
What is the best, in Perl, way to get the selected values of a multiple select form field?
<select name="mult" multiple="multiple">
<option value="1">Opt. 1</option>
<option value="2">Opt. 2</option> <!-- selected -->
<option value="3">Opt. 3</option>
<option value="4">Opt. 4</option> <!-- selected -->
<option value="5">Opt. 5</option>
</select>
I get regular form fields like this: $param1 = param('param1');
If you are using the CGI Module (and I really hope you are) then you can access the multiple values by assigning the param hash to an array and CGI does the rest. So in your example:
my #mult = $q->param('mult');
will store the selected values (2, 4) in the #mult array.