This works fine:
<label>myText</mytext>
Is it possible to have short form? This doesn't work:
<label myText>
What you are trying is an Invalid HTML. As per W3c
A label element must have both a start tag and an end tag.
So you need to write that in the lengthy way if you are going with traditional HTML. If you use some templating lib / Pre-Processor than it might give you additional features which will further let you write compact/tighter syntax.
For example you can use HAML, Slim and so on..
If we take Slim as an example here, all you need to write is
label Username
This will further compile to .. Demo (Click on compile please)
<label>Username</label>
Further if you want to add attributes to your label
label for='username' Username
Will compile to
<label for="username">Username</label>
I know only one shorting:
<!-- from large -->
<label for="foo">Question:</label>
<input id="foo" value="answer" />
<!-- shorten me -->
<label>Question:
<input value="answer" />
</label>
Related
I'm trying to append a <br> after every input line in a form, but Thymeleaf keeps giving me parsing error.
Here is the code piece that I'm having trouble with:
<form th:if="${not #lists.isEmpty(brands)}">
<input th:each="brand : ${brands}" type="checkbox" th:value="${brand.name}" th:utext="${brand.name + <br>}" />
</form>
If I add the <br> tag outside of input tag, it doesn't add it to each line.
Thanks in advance
I think you may be going about this in the wrong way.
th:utext would insert that within the <input> node. But, according to the HTML5 Spec, nothing goes in an <input> tag ("Content model: Empty.")
I think you want something more like this:
<form th:if="${not #lists.isEmpty(brands)}">
<th:block th:each="brand : ${brands}">
<label th:for="${#ids.next('brand')}" th:text="${brand.name}">Brand A</label>
<input type="checkbox" th:id="${#ids.seq('brand')}"
name="brand" th:value="${brand.name}"/>
<br/>
</th:block>
</form>
If you're using Spring MVC, you may also find this example helpful: http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#checkbox-fields
I am working on an assignment and am a little lost. The question states:
Create a label element with the text Username. Within the label element, insert
an input box for the username field. Make the field required and add the title Supply
your username
Here is what I have. I am mainly confused on the title portion. Any help is greatly appreciated, and feel free to correct me on the other parts. Thank you
<form id="survey" name="survey"
action="www.sblogger/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS"
<label>
Username
<input id="username">
required="required"
</label>
</fieldset>
</form>
You just need to add a title attribute on the input field. Also the label tag can stay on it's own, which leaves to:
<form id="survey"
name="survey"
action="www.sblogger/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS">
<label>Username</label>
<input id="username"
title="Supply your username"
required>
</fieldset>
</form>
The assignment is not well-defined, since it does not say what kind of a title should be included. It may refer to an advisory title that may be presented to user in some situations (e.g., on mouseover), as assumed in #Jeffrey’s answer. It may also refer to text that appears inside the input box when it is empty, in which case you would use the placeholder attribute. It can also refer to visible text before the input box; this would be the most reasonable setup. Even then, there are several alternatives. It could be just text before the label and the input box, or it could be wrapped in a heading element, or even a legend for a fieldset. The following example is based on the wild assumption that such a legend is desired (which might be a wrong guess if you have actually been told to use the fieldset element, as you are using, although there is no reason to use it in a simple case like this).
<form id="survey" name="survey"
action="http://www.example.com/cgi-bin/subcomments"
method="post">
<fieldset id="commentFS">
<legend>Supply your username</legend>
<label>
Username
<input id="username" name="username"
required="required">
</label>
</fieldset>
<input type="submit" value="Submit">
</form>
Notes: The attribute required="required" (or just required unless you have been told to use XHTML syntax) must appear inside the <input ...> element, not after it. And the input element needs a name attribute, otherwise the data in it will not be sent at all to the server.
I need to convert to HTML the design, among other things I need to make feedback form which has this element
What tags do I need to use for the layout of this element?
Each one is <input type=file>. You'll want a class to capture them all together say...class="photo".
You'll probably wrap it all in a <div> and it should definitely use some Javascript to replace those '+' images with the actual photo using AJAX (would go to server, get condensed/scaled as needed and sent back to browser).
<div class="photos">
<form name="myform" action="usefulPage.php" method="post">
<input type="file" name="pic[]" class="photo" />
...more
<input type="submit" value="Submit" id="submit-button" />
</form>
</div>
And there's a ton more stuff to do (CSS, JS, more HTML, etc). This should just get you barely started.
PS - use the pic[] in "name" so more than one of them turns into an array and they name themselves automatically by number.
Hello,
I am wondering if it is possible to change the wicket output html code. e.g. for the component "CheckBoxMultipleChoice" you will get the following html output.
<span wicket:id="letters">
<input name="letters" type="checkbox" value="0" id="letters_0"/><label for="letters_0">fff</label><br/>
<input name="letters" type="checkbox" value="1" id="letters_1"/><label for="letters_1">aaa</label><br/>
<input name="letters" type="checkbox" value="2" id="letters_2"/><label for="letters_2">bbb</label><br/>
<input name="letters" type="checkbox" value="3" id="letters_3"/><label for="letters_3">ccc</label><br/>
<input name="letters" type="checkbox" value="4" id="letters_4"/><label for="letters_4">ddd</label><br/>
</span>
if i dont want the <br/> tag, what can i do?
regards
It depends on the component.
For anything Panel-based, you can always subclass the component (MyPanel.java) and supply a different markup file (MyPanel.html). As long as you have the same wicket:ids in there, it works fine.
For built-in Wicket components that have markup elements embedded in their source code, like CheckBoxMultipleChoice, you're at the mercy of the custom API of the component. In your case it looks like you want CheckBoxMultipleChoice#setSuffix.
No, extract from the documentation
Components may alter their referring tag, replace the tag's body or insert markup after the tag. But components cannot remove tags from the markup stream. This is an important guarantee because graphic designers may be setting attributes on component tags that affect visual presentation.
however if you want add/remove new line spaces between your components you can change the display of component to block/inline
#Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
//block or inline
tag.put("style", "display:block");
}
or use a CSS class
I already posted a similar question and got a jQuery solution that works. Now I want to do it with only CSS/HTML. I saved twitter's homepage locally and deleted all the js scripts and noticed that the effect I'm trying to achieve is with CSS/HTML (when you click on the username/pass the values "Username"/"Password" stay there until you enter text).
I'm a newbie at these kind of new CSS/HTML effects and have spent the last couple of hours trying to replicate it with no success.
Here's the html of twitter's login form:
<form action="#" class="signin" method="post">
<fieldset class="textbox">
<div class="holding username">
<input type="text" id="username" value="" name="session[username_or_email]" title="Username or email" autocomplete="on">
<span class="holder">Username</span>
</div>
<div class="holding password">
<input type="password" id="password" value="" name="session[password]" title="Password">
<span class="holder">Password</span>
</div>
</fieldset>
<fieldset class="subchck">
<label class="remember">
<input type="checkbox" value="1" name="remember_me">
<span>Remember me</span>
</label>
<button type="submit" class="submit button">Sign in</button>
</fieldset>
I've looked over the site's CSS but it's 10,000 lines and very complicated. How should the CSS look like? Or could you point me out to a tutorial on how to achieve the same effect as this is driving me nuts?
Thank you very much,
Cris
Set the HTML autofocus attribute:
<input type="text" placeholder="Type here ..." autofocus="autofocus" />
You can target elements that are focused or blured like so:
input:focus {color:red;}
You now need to nest the CSS to hide the span called holder inside the input.
span.holder input:focus {visibility:hidden;}
I have not tried this, but it would be something like this.
To clarify, I have just pulled the JavaScript twitter use and the source for their home page and I can confirm that they are using the following JavaScript function for focus on the field
inp.focus()
The JavaScript is quite lengthy but it looks like after a quick read that they are using jQuery that is setting focus based on the class being username.
I just looked at the autofocus property suggested by another poster and this method has worked for me in my web app currently under development.
The code for this is
<input type="text" id="username" value="" name="session[username_or_email]" title="Username or email" autocomplete="on" autofocus>
Note, per the documentation at the W3C website, the autofocus property can only be used once on the page. I have put it into a form that is hidden and shown in an inline element using Fancybox.
The grayed out text in the input field can be done with the place-holder element, something I'm already using, add the following into your input element
placeholder="Username"
NOTE: Both placeholder and autofocus are HTML5 properties and may not be supported by all major browsers yet, this is why JavaScript is still being used by sites like twitter.
The styling is done based on CSS/CSS3 greatly, an excellent resource is W3Schools. I would recommend for what you're wanting to achieve start at the CSS3 section looking at borders.
Another resource that is excellent but hasn't been updated for about a month and a half sadly is doctype.tv. Nick has some fantastic advise regarding styling your website along with some great insight into design.
Judging by the bolded text in your question (when you click on the username/pass the values "Username"/"Password" stay there until you enter text), I'm guessing what you want is the placeholder attribute, which #phihag has in his example.
<input type="text" placeholder="This text will disappear" />
The placeholder attribute works without Javascript in browsers that support it. For older browsers, you'll need some Javascript, and this is probably what Twitter is doing in their code.
See the Wufoo page on the Placeholder Attribute for more details, including how to do a javascript fallback and what browsers it is currently supported in.
See also this demo which shows how to style the ":placeholder" and ":active" states (at least for webkit and mozilla).