Change a labels for tag using Prototype? - prototypejs

I know I can change a labels id like this:
$(someid).id = 123;
How can I change the for, too?
This is the code I have:
<label id="10" for="xyz">
sometext
</label>
How can I change the for from xyz to abc using Prototype?
Thanks :)

$(someid).writeAttribute('for', 'abc');

Related

Angular material group dropdown - How to add group name to text box

I have a material group dropdown designed just like the official documentation (here).
Question is : How can I display the selected item text along with group name.
ie; If I select Bulbasaur from 'Grass' group, as in the image, it should show 'Grass - Bulbasaur' instead of just 'Bulbasaur'. Any ideas?
Update: I have found a work around. Anyone fiddling around with the same issue can do this css hack in the mean time,
<mat-form-field>
<mat-select placeholder="Pokemon" [formControl]="pokemonControl">
<mat-option>-- None --</mat-option>
<mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
[disabled]="group.disabled">
<mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
<span style=display:none">{{group.name}} -</span>{{ pokemon.viewValue }}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>
It looks like the proper way to do this is to set "custom trigger text":
See the examples for the MatSelect instead of the overview
So you would do something like this:
<mat-form-field>
<mat-select placeholder="Pokemon" [formControl]="pokemonControl">
<mat-select-trigger *ngIf="pokemonControl.value; let pokemon">
{{ pokemon.parentViewValue }} : {{ pokemon.viewValue }}
</mat-select-trigger>
<mat-option>-- None --</mat-option>
<mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
[disabled]="group.disabled">
<mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon">
{{pokemon.viewValue}}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>
Take note of two things:
Obviously the mat-select-trigger tag... I am using the full pokemon model, you will need to add either a reference to the parent group or, like I have done, add the parent view value in each pokemon. You can do either when you actually construct the model
My [value] for the mat-option tag is pokemon instead of pokemon.value as I need the full model

XPath Without Selector

Suppose I have following code:
<div class="Class">
<h3>First Title H3</h3>
First Description <br />
Choose Option:
<select id="Id" name="Name">
<option value="Value1">Option1 $Price1</option>
<option value="Value2">Option2 $Price2</option>
<option value="Value3">Option3 $Price3</option>
</select>
<h3>Second Title H3</h3>
Second Description Link
</div>
What's the Xpath to print "First Description" only?
What's the XPath to print "$Price1" only (without/exclude "Option1")?
Thanks for your help.
I'm not sure what is your desired output, but here is what should help you.
following-sibling::text() would help you to check the First Description:
//div/h3[contains(following-sibling::text(), "First Description")]
For the first option of the select tag, I would rely on the select's id attribute and option's value attribute:
//select[#id="Id"]/option[#value="Value1"]/text()
Solved based on this answers: using XPath: how to exclude text in nested elements and XPath: select text node and Get second element text with XPath?
String value = driver.findElement(By.xpath("//*[#value ='Value1']").getText();
String strarr[] = value.split(" ");
System.out.println("Price1 :"+ strarr[1]);
I think this will work, we are finding the text and splitting with space.

How to check of a Node is inside a form tag?

Using XPath, how do I determine if a node is within a form tag? I guess I am trying to locate the form tag of its ancestor/preceding (but I couldn't get it to work).
example 1:
<form id="doNotKnowIDofForm">
<div id="level1">
<span id="mySpan">someText</span>
</div>
</form>
example 2:
<form id="doNotKnowIDofForm">
This is a closed form.
</form>
<div id="level1">
<span id="mySpan">someText</span>
</div>
</form>
I can use xpath "//span[id='mySpan']" to locate the span node. But I would like to know if mySpan is inside a form (I do not know the id of the form). I have tried "//span[id='mySpan']/preceding::form/" and "//span[id='mySpan']/ancestor::form/"
Thanks in advance.
EDIT: I would like the XPath to select the myForm form tag in Example1 but NOT in Example2
I'm not 100% sure from your description whether you're looking to select the form element, or the span element. It seems more likely that you're going for the form, so I'll address that first.
Your XPath with the ancestor::form would have been ok if it didn't have the slash at the end, but it's more roundabout than it needs to be. I think this is a better way:
//form[.//span/#id = 'mySpan']
or this:
//form[descendant::span/#id = 'mySpan']
To produce an XPath that locates certain nodes only if they are within a form, you would put the ancestor::form inside the predicate:
//span[#id = 'mySpan' and ancestor::form]
or you can do this, which would again be more straightforward:
//form//span[#id = 'mySpan']
Your own attempt
//span[id='mySpan']/ancestor::form/
looks fine to me.
You can simply use,
"form//span[id='mySpan']"

Why is #Html.Label() removing some characters

When I use the following code in my razor view it renders <label for=""> someText</label> and not <label for="">1. someText</label> but I can't figure out why 1. is removed while rendering.
#Html.Label(String.Format("{0}. someText",1))
Edit:
The following code renders <label for="">1# someText</label> as expected.
#Html.Label(String.Format("{0}# someText",1))
You are misusing the Html.Label method. It is for:
Returns an HTML label element and the property name of the property
that is represented by the specified expression.
That's why it gets confused if you have a point . in the first parameter because it expects a property expression there.
However, you can use the second overload:
#Html.Label("", String.Format("{0}. someText",1))
Or just write out the HTML:
<label>#String.Format("{0}. someText", 1)</label>
You can avoid using the "Html Helper's label" and directly use html "label" and place whatever you want to display correctly. It can also save some time ;)
The syntax which you are using is wrong or We can say that this is not a way to use property with RAZOR syntax.
You ca use this that may be help full for you.
**
#Html.LabelFor(model => model.PropertyName,
String.Format("{0}. " + #Model.PropertyName.ToString() + ",1))
**
I was using this for a data table that contained a double (Lat/Long) and saw this same problem. Thanks for the tips (I am not allowed to comment).
For me, the problem was solved ..
#foreach (var cell in item.ItemArray)
{
<td>
#Html.Label("",cell.ToString().Trim())
</td>
}

following-sibling::text() only if contains needle

In PHP-Xpath i get text between <br /> tags like:
//*/br/following-sibling::text()
How can i get this text only if contains 'needle'?
Something like br[contains(.,'needle')] - or - following-sibling::*contains(.,'needle')/text()
Appreciate any help
Use:
following-sibling::text()[contains(., 'needle')]

Resources