In a screen class which extends LiftScreen, I defined a text field:
class MyScreen extends LiftScreen {
val stuffName = text("Stuff Name", "", trim, valMinLen(2, "2 chars at least"),
"class" -> "input-xlarge")
}
It generates the html as following:
<input style="float:left; margin-right: 10px" id="F666221395073GHLIXL" value=""
class="input-xlarge" type="text" name="F666221395059FXOCFK">
You can see the id
and name
attributes, have different generated values. What are the two attribute values used for? Why they are different? I thought they should be the same.
Update
Lift will use these generated values to match a function it stores on the server-side and run it.
For a single input, one unique value is enough for this, maybe id
, maybe name
, but why there are two different values?
If one of them are useless, lift doesn't need to generate it at all.
In HTML forms, id
and name
are not the used for the same things. XML requires that each id
is unique. This is not the case for name
. Consider the following form:
<form ...>
<input type="radio" value="1" name="option" id="option1" />
<label for="option1">Option 1</label>
<input type="radio" value="2" name="option" id="option2" />
<label for="option1">Option 2</label>
<input type="radio" value="3" name="option" id="option3" />
<label for="option1">Option 3</label>
</form>
The name
of the three input
tags must be the same to achieve the desired selection behavior (one out of the three). However, the id
field needs to be unique (by specification and for the label
tags).
Lift obviously aims to generate HTML that can support such a use case and hence has to generate id
and name
separately in this case. What you see is probably just a result of generalization (nothing requires name
and id
to be equal after all).