HTML5 <input> required attribute but not inside <form> [duplicate] - html

This question already has answers here:
html5 input type required without a form. Does it work?
(3 answers)
Closed 7 years ago.
The Required attribute works great inside the form Tags:
<form>
<input type="text" name="user" required>
</form>
But can I use the required attribute if I cannot wrap it as a form? Outside of the form this input required does not work for me:
<input type="text" name="user" required>
I can replicate it with JavaScript but Id like to know if outside form is possible

The "required" attribute only works on form submit and since your input has no form the browser does not know what to validate on submit.
What the w3c says about "required":
When present, it specifies that an input field must be filled out before submitting the form.
This would only be possible with JS like:
document.getElementById('your_input_id').validity.valid
Already discussed here 4 years ago:
html5 input type required without a form. Does it work?

Related

Required attribute in Html

can I use required attribute here? when I am not using form tag ? whether required works only inside form tag?
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname" required>
No, as mentioned here:
The "required" attribute only works on form submit and since your
input has no form the browser does not know what to validate on
submit.
Here is also what W3C says:
When present, it specifies that an input field must be filled out before submitting the form.
So — assuming you aren't intending to use some sort of JS solution — no form, no required.

Can I have a form input that doesn't get serialized/submitted on form submission without JS? [duplicate]

This question already has answers here:
Stop an input field in a form from being submitted
(14 answers)
Closed 1 year ago.
Let's say I have a form like this:
<form id="something_form">
<input type="text" id="thing1" name="thing1">
<input type="hidden" id="thing2" name="thing2">
<input type="text" id="secret" name="secret">
<input type="submit">
</form>
Currently I have JS that listens for the submission event, takes the info in the secret input, and does some work before adding it to thing2. The server never uses or needs secret. I can clear the data in secret before form submission, so it's just thing1=abc&thing2=abc&secret=, however if the user has JS off, then the form submission request would have thing1=abc&thing2=&secret=secret.
Is there a pure HTML way to make an input work as normal, but not get serialized/submitted on form submission? I know that I can remove name="secret" to achieve this, but that loses me any functionality that relies on the name attribute.
My idea for a solution is to render the page without the name="secret":
<input type="text" id="secret">
then add it via JS(since if the user has JS on, it would run):
document.getElementById("secret").setAttribute("name", "secret");
But I'm curious if there's another solution for this.
One option is to use the form attribute. An input with the form attribute set counts as part of the form whose ID matches its form attribute, NOT as part of the form that it's actually inside of.
Example: <input type="text" name="fish" form="bogus"> won't get submitted along with the rest of the form, unless the form has id="bogus" for some reason.

Disable auto fill of input tag in html? [duplicate]

This question already has answers here:
How do you disable browser autocomplete on web form field / input tags?
(101 answers)
Closed 3 years ago.
I have a webpage taking a new user name & password as input. For scripting, I am using AngularJS.
<div class="form-group">
<input ng-model="prc.userName" placeholder="User Name" type="text" class="form-control" autocomplete="nope" required autofocus />
</div>
This input box always gets auto-filled, I don't want it to get auto-filled.
Question reviewed prior: How do you disable browser Autocomplete on web form field / input tag?
// These attributes do not work
autocomplete="off"
autocomplete="false"
My chrome version: Version 73.0.3683.103 (Official Build) (64-bit)
How can I do that?
Yes this is a known error and it can be really annoying. for some reason autocomplete='false' and autocomplete='off' aren't working at all in chrome.
The only known method to get rid of it is to use autocomplete='new-password', this will deactivate the autocomplete!
Cheers
Add autocomplete="off" onto (form) element;
Add hidden (input) with autocomplete="false" as a first children element of the form.

How to disable input field history using html [duplicate]

This question already has answers here:
How do you disable browser autocomplete on web form field / input tags?
(101 answers)
Closed 6 years ago.
I want to disable the previously searches from my text input field. You know, the little box that pops up under the search bar with suggestions while you're typing ? Here, I'll attach a screenshot:
Simply set autocomplete="off" on your input element.
<input name="yourname" type="text" autocomplete="off"/>

Customize form/input in validation in HTML 5 [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
HTML5 form required attribute. Set custom validation message?
in HTML 5 form validation
<form>
<input type="txt" required id="username"/>
</form>
this required filed will always shows the message "Please enter filed"
Is there a way to customize this message ?
Not all browsers will support this attribute, Firefox does support it, IE and chrome no.
I dont know about the other browsers.
using value="Your value" mentioned above won't work. i just tried it.
i guess we have to wait till HTML5 becomes stable. to find out
<input type="txt" required id="username" value="Your value" />