I'm making some functional tests with symfony2. I want to select a radio button in a basic form :
<form method="post" action="mylink">
<input id="position_51" type="radio" name="user_position" value="51">
<input id="position_52" type="radio" name="user_position" value="52">
<input id="position_54" type="radio" name="user_position" value="54">
<input id="position_57" type="radio" name="user_position" value="57">
<button id="bt_submit" type="submit">Submit</button>
</form>
So I select the form
$buttonFrom = $client->getCrawler()->selectButton('bt_submit');
$form = $buttonFrom->form();
Now, if I want to select radio with a specific ID, like "position_54" and tick it. How to do? In all examples I found, tick() seem to be used in the name attribute of the input... That not help me in a radio button case.
$form['user_position'] doesn't seem to be a array...
Thanks
As said in the symfony doc about testing, you can select an option or a radio this way :
$form['user_position']->select('51');
Here is the API for the ChoiceFormField.
Related
How to email validation in angular 13 version. I have used a input field and submit button. If email validation failed then alert show.
<input type="email" [pattern]="emailPattern"
class="form-control adduser" placeholder="Email address"
[(ngModel)]="newEmailId">
<button type="button" class="commonnew-btn" (click)="addNewUser()">Add User</button>
Please find the ts file code
emailPattern = "^[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,4}$";
addNewUser(){
}
How to write in this method. Please give me advice. Not using form group or form tag and reactive form. Only this condition.
I have an angular 7 reactive form, input field in this form is to let user see and modify time and then using Save() save it back to our db, the problem is that user can enter any none sense numbers in this field which dose not make sense in terms of Time.(like hours should be 1-24, Minutes 1-60)
My question is how can I validate what user entered into time field and if its valid then let Save btn be active?
Note: Based on my testing even though its none sense time entry but while trying to save its not saving to db and its probably sql not letting that happen.
I googled but i could not find anything, also angular has only email Validators which u can put while defining form.
this is my form defination
timeForm: FormGroup = new FormGroup({
Id: new FormControl(''),
Time: new FormControl(''),
});
and this is my HTML side
<form style="background-color: aliceblue;" [formGroup]="service.timeForm">
<mat-grid-list cols="1" rowHeight="120px">
<mat-grid-tile>
<div class="form-controles-container">
<input type="hidden" formControlName="Id" />
<mat-form-field>
<input formControlName="Time" matInput placeholder="Time" />
</mat-form-field>
<div class="button-row">
<button mat-raised-button color="primary" type="submit" (click)="Save()">Save</button>
<button mat-raised-button color="warn" (click)="Cancel()">Cancel</button>
</div>
</div>
</mat-grid-tile>
</mat-grid-list>
</form>
I need some sort of validation when user punch in any input which dose not make sense in Time my Save btn should not be activated.
I appreciate your help and guideline.
You can use the HTML type="time" or if you want more you can simply use a library like: JsDaddy/ngx-mask found on Github. Use it like this:
HTML with MatInput:
<input formControlName="Time" matInput placeholder="Time" type="time" />
With ngx-mas:
<input formControlName="Time" matInput placeholder="Time" mask="Hh:m0" />
Adding type="time" in all input time type use cases always help.
I Want to make radio buttons from form with one choose only. Single Options with
A. Exemple One
B. Exemple Two
C. Exemple Three
D. Exemple Four
If you choose one questions A, you cant to change your opinion. Thanks for help.
http://preview.ipanelthemes.com/fsqm/form-with-latex-options/
Here you have exemple.
The easiest way to do this would be using JavaScript to add an event listener so that when a user clicks on one of the radio options, the script then will set the "disabled" attribute in place.
Given the following HTML:
<form>
<input type="radio" name="creditcard" id="visa">Visa
<input type="radio" name="creditcard" id="mstrcrd">MasterCard
<input type="radio" name="creditcard" id="amex">American Express
<input type="radio" name="creditcard" id="dscvr">Discover
</form>
You could use the following JavaScript:
var radioInputs = document.getElementsByName("creditcard");
function toggleDisable() {
for (i=0; i<radioInputs.length; i++) {
radioInputs[i].disabled = true;
}
}
for (i=0; i<radioInputs.length; i++) {
radioInputs[i].addEventListener('click', toggleDisable, false);
}
Keep in mind that the .addEventListener method will not work in IE8 or prior. You will either need to write an if statement checking for the .addEventListener or use jQuery.
Let me explain myself i'm doing an Application in VB.net asp.net and I Want to put a CheckBox List instead of Radio Button cause my customer want it square and not round. The Only problem i got is when i check a Checkbox the other one are not unchecked. I'm not sure im clear enough feel free to ask me question.
As seen above, this isn't recommended. However if you have to do it, here's how I made it in jQuery:
Create your checkboxes and assign them classes
<input type="checkbox" class="cbr"/>CB 1
<input type="checkbox" class="cbr"/>CB 2
<input type="checkbox" class="cbr"/>CB 3
<input type="checkbox" class="cbr"/>CB 4
<input type="checkbox" class="cbr"/>CB 5
And the jQuery
$(".cbr").click(function() {
$(".cbr").prop("checked", false);
this.checked = true;
});
Here's a demo: http://jsfiddle.net/g2YMs/
Also, if you're creating the checkboxes with ASP.NET controls, you should select them using:
$("#<%=IdOfControl.ClientID%>")
This is, of course, if you decide to go the jQuery way.
Another jQuery noob question - what am I doing wrong??
I have some HTML markup rendered by ASP.NET 3.5 webforms which looks like this:
<input id="ctl01_cphContent_pnlBasicInfo_chkRC"
type="checkbox" name="ctl01$cphContent$pnlBasicInfo$chkRC" />
<label for="ctl01_cphContent_cntPromos_pnlBasicInfo_chkRC">Recurrent Charges</label>
<span id="ctl01_cphContent_cntPromos_pnlBasicInfo_lblPromoValidFor"
class="rcPromo">Validity:</span>
<span class="rcPromo">
<input id="ctl01_cphContent_pnlBasicInfo_rbnDiscountValidFor"
type="radio" name="ctl01$cphContent$pnlBasicInfo$discountValidFor"
value="rbnDiscountValidFor" checked="checked" />
<label for="ctl01_cphContent_cntPromos_pnlBasicInfo_rbnDiscountValidFor">valid for</label>
</span>
<span class="rcPromo">
<input id="ctl01_cphContent_pnlBasicInfo_rbnDiscountValidUntil"
type="radio" name="ctl01$cphContent$pnlBasicInfo$discountValidFor"
value="rbnDiscountValidUntil" />
<label for="ctl01_cphContent_cntPromos_pnlBasicInfo_rbnDiscountValidUntil">valid until</label>
</span>
<input name="ctl01$cphContent$pnlBasicInfo$txtDiscountMonths" type="text"
id="ctl01_cphContent_pnlBasicInfo_txtDiscountMonths"
class="textbox" class="rcPromo" originalValue="" style="width:30px;" />
<span id="ctl01_cphContent_cntPromos_pnlBasicInfo_lblMonths" class="rcPromo"></span>
<input name="ctl01$cphContent$pnlBasicInfo$txtDiscountUntil" type="text"
id="ctl01_cphContent_pnlBasicInfo_txtDiscountUntil"
class="textbox" class="rcPromo" originalValue="" style="width:150px;" />
I have a checked "chkRC" which I want to trap and use to enable/disable other UI controls
I have a number of labels, input (type=radio) and input (type=text) UI controls. These are all marked with the "rcPromo" dummy CSS class
I have a CSS class called "textbox" for the normal textbox and "textboxDisabled" for the disabled state of the textbox, in an externally referenced CSS file, that work OK (when used in server-side code, that is)
What I'm trying to accomplish in jQuery is this: when the "chkRC" checkbox is disabled, I want to disable all relevant UI controls.
My jQuery looks like this:
$(document).ready(function() {
$("#<%= chkRC.ClientID %>").click(function() {
$('.rcPromo > :label').toggleClass('dimmed');
if (this.checked) {
$('.rcPromo').removeAttr('disabled');
$('.rcPromo .textboxDisabled').addClass('textbox').removeClass('textboxDisabled');
}
else {
$('.rcPromo > :input').removeAttr('checked');
$('.rcPromo .textbox').addClass('textboxDisabled').removeClass('textbox');
$('.rcPromo').attr('disabled', true);
}
});
});
It works fine for the labels and the radiobuttons - but I just can't get it to work with the textboxes - they just stay the same all around, nothing changes (they don't get disabled and they don't change their appearance to indicate that they're disabled, either).
I don't understand this - I do see several (a few more than in the sample) textboxes, which are <input type="text"> in HTML, and they do have the class="rcPromo" and class="textbox" on them - so why doesn't jQuery find and update those?
Any ideas?
Marc
I can't think of a way to augment the css class names that are assigned to controls from the skin file (phoenix is correct, the class names need to be added in the same attribute).
I can think of a few workarounds though:
--> You can wrap all the textboxes you want disabled in a div with a given class:
<div class="disable_textbox"><asp:textbox id="".../></div>
and then disable them by selecting:
$('.disable_textbox input').attr('disabled', true);
--> You can include character strings in the ID of the textboxes you want disabled:
<asp:textbox id="txtDiscountUntil_DisableMe" ... />
and then disable them like so:
$("input[id*='DisableMe']").attr('disabled', true);
--> You can add a custom attribute to your textbox:
txtDiscountUntil.Attributes.Add("disableme", "true");
and then disable them like so:
$("input[disableme='true']").attr('disabled', true);
Your HTML markup is not the correct one.
You can't add two classes like the one in your code.
Two classes can be added like this
<input type="text" class="Class1 Class2" />
and not like
<input type="text" class="Class1" class="Class2" />
Why don't you use hasClass to check whether the element has this class set or not?
I think you have to give this in an OR condition for the two classes.