I'm trying to create a password textfield and I want the user to enter at least 8 characters. I really like the way the visible maxLength character counter on textfields work when a maxlength is set, and I was wondering if there is any equivalent for a minimum length. Thanks!
You have to use TextFormField instead of TextField.
Check this SO post:
For Text Field Validation use TextFormField instead of TextField.
TextFormField needs to be wrapped with Form widget (If there are
two ore more textformfields you can wrap their parent widget with form
widget).Form widget requires key and autovalidate boolean (it's
optional but it's recommended to show message to user when they
haven't validated and as soon as they validate message stops showing).
We create two variables and assign it to Form.Then we need a
validator in which we validate according to our requirements.(If you need to add more validations you can add multiple if
conditions.).Finally on field submitted we check if user has validated
the form if validated we perform our desired action else we set
autovalidate variable to true to perform autovalidation.
E.g.
TextFormField(
...
validator: (String value) {
return value.length < 8 ? 'Minimum character length is 8' : null;
}
)
Related
Sometimes it would be more convenient to customize a validation message with a label rather than the property. For example:
Let's imagine there is a field in form named 'x' but the UI interface shows it as 'Name' (the field label). But, as fas as I understand, the customizazion of a validation message does allow only the use of properties, that is name fields.
validations: {
required: "The field {property} is required.",
}
Is there a way to use a label to customize the above message?
Thank you!
I've signup form. In input field when I used to write previous username then it gives me available username list which is coming from API.
My question is that how to change input field data when I used to click available username in vue js?
I'm thinking you want to do something like...
User types in a username, somewhere in the UI you show a list of available usernames, user clicks preferred username, input box is updated with selected username.
Without seeing any of your code it's difficult to give you an specific answer, however, what I would do is:
Create the input box. Bind this to an object in your script:
HTML:
<input v-model="username"/>
Script: username: string = ""; availableUsernames: [""];
Create a button next to the input box, when it's pressed it calls your API and returns the available usernames and applies to to availableUsernames.
The available usernames are returned as an array and the array is displayed on your UI as a list.
When you click on an object in the list on your UI, this calls a function which updates the username property. e.g.:
<li v-for="u in usernames"><a #click="applyUsername(u.description)">
applyUsername(description: String){ this.username = description }
I'm trying to find a way to to exclude one field input in my form that is disabled and contains the value of a users ID number
I would like to know how I can tweak this.$refs.form.reset(); because it works perfectly but it clears EVERYTHING and I wish to contain the ID value and resets the rest of the fields like name surname age income etc
The reason why I the ID is important is that the user gives this in a sign-up step at the start and this form that I am talking about is located somewhere else to complete his profile I don't want to ask the user again to type his ID in again.
If anyone knows how to accomplish this it would be a great help
The reset method of the form simply looks at all the inputs bound to it and resets each one within a loop then empties the error bag, observe:
reset (): void {
this.inputs.forEach(input => input.reset())
this.resetErrorBag()
},
There's no reason you can't do the same, except for when they're disabled:
resetForm() {
this.$refs.form.inputs.forEach(input => {
if (!input.disabled) {
input.reset()
}
})
this.$refs.form.resetErrorBag() // necessary to remove validation errors after the field values are removed
}
Then you can call that function (against your Vue instance, not your VForm) with this.resetForm() and it should work out the way you want.
Disclaimer: Can't test it at the moment. input.disabled may not be readily available and may require further inspection of the input element.
I have an hidden input field which value changes according to the option selected in a s:select in Struts 2. Then, there's a button that points to an action like loadData.action.
I would like to add to this action a parameter named item.id with the value of the hidden field as its value, a value changing each time I select a new option.
I've tried to use an s:param with an s:property inside and the name or the id of the s:hidden, but it doesn't print the value after the = sign.
How can I do to achieve this result? loadData.action?item.id=12 where 12 is the value of s:hidden name="item" id="item" ?
Please Provide complete action link and which value to be change also your HTML structure, so it will be easy to answer your question
Assuming your HTML structure's elements, I have tried to answer your question
You can change action using jQuery on change event of your <s:select>
Have a look at https://jsfiddle.net/shantaram/qy9rew4v/
$('#id-select').change( function () {
var newAction = $('#id-form').prop('action');
newAction = newAction.substring(0, newAction.lastIndexOf('='));
$('#id-form').prop('action', newAction+"="+varItemId);
//varItemId is value of your hidden field
//which you want to change Dynamically
});
provided:
id-select -> Id of your <select> element
id-form -> Id of your <form> element
I need to create a validation to textfield only allow me to enter text no number and no symbols. text only.
with the following rule, where attribute is the name of the textfield
array('attribute', 'match', 'pattern'=>'/^[a-zA-Z]+$/'),
Check out this link to see all build in validation options: http://www.yiiframework.com/wiki/56/