I have an input field of number type.I want that anyone can only enter 4 digits on that field. How Can I achieve it?
To prevent more than 4 characters from being entered in the input field, set a maximum length:
<input maxlength="4">
This is the most basic way to achieve that. There are other ways to do it depending on whether or not you are using template or reactive forms. See the Angular guide for form validation: https://v5.angular.io/guide/form-validation.
Related
Is it possible to add a session in cq:dialog which renders whatever data is supplied in the fields and previews it out in real time. In the simplest of scenarios, I need to add two numbers and when I enter both the numbers the cq:dialog should preview it's output as 4. There should be two sessions in the the cq:dialog, like two columns, the left one to enter value to the fields and the right to display the rendered output. How to achieve this? Is it possible to?
You can make use of "event handlers". Adobe docs has a simple example using JQuery that you can customize for your requirement.
https://helpx.adobe.com/experience-manager/using/creating-touchui-events.html
I'm using Angular 6.0.9 and Angular Material 6.5.4. In my form I have an ngFor loop for the inputs with an errorStateMatcher to validate the input.
The problem is that if the content of an input field is invalid, all other fields will also be marked as invalid (even if they are not dirty). I want to make sure that only the current field that is actually invalid is marked as red.
See a self-explanatory example on stackblitz:
https://stackblitz.com/edit/angular-s1jyhw?file=app%2Finput-error-state-matcher-example.html
Your inputs all share the same form control emailFormControl. You need a separate form control for each input. It is okay to use the same ErrorStateMatcher but not FormControl
I have Polymer application and I want to check if given inputs are NOT EMPTY on form submission. I have some inputs set to required but I don't have any way to check if those fields are NOT EMPTY. I can only check if given pattern is matched by checking invalid attribute but even for required fields pattern is .*.
Is there any wait to do it? Or is it in beta and this feature has not been implemented yet?
Polymer.dart <= 0.16.x
You can set a pattern yourself
<paper-input floatinglabel
label="Some label"
value='{{someValue}}'
pattern="^.+$"
error="Input required">
</paper-input>
Or see
Taking total control of PaperInput validation
for complete control of validation.
I have a simple feedback form in a Kentico CMS site.
There are two inputs and a submit button. One of the inputs is a yes/no radio button selection and the other is a text area input. (please see screenshot).
I want the user to be able to submit the form only when at least one of the following 3 criteria are met:
'Was this page helpful?' was answered.
The text area value is not blank and the value does not equal the default text value which is 'How can we improve this page? Providing feedback helps us to improve this information'
Or, both criteria in 1 and 2 are met.
Basically, I want them to answer at least one of the inputs.
Is this type of validation possible using Kentico forms/online form web part?
Screenshot of form (may be of use):
I contacted Kentico about this functionality and their response is below:
Regrettably, this type of validation is not provided. Kentico CMS
perform validation for each built-in control separately.
In general, you have two options. The first one is to implement the
OnBeforeValidate or OnAfterValidate events which give you the ability
to perform a custom validation if necessary. You can access each field
as follows:
string answerText =
ValidationHelper.GetString(viewBiz.BasicForm.Data.GetValue("answerText"),
"");
If the validation fails, you need to set the StopProcessing of the
BizForm control to true:
viewBiz.StopProcessing = true;
More information about customization possibilities related to BizForm
can be found here:
http://devnet.kentico.com/docs/devguide/index.html?api_bizforms_customization_possibilities.htm
Another way would be creating a custom form control just as it is
described in the documentation:
http://devnet.kentico.com/docs/devguide/developing_form_controls.htm
The form control would allow users to specify both fields and
therefore you can peform the custom validation (IsValid method)
according to your requirements.
To set a field other than the field for which the for control is used,
you need to implement the GetOtherValues method.
Then, just disable the other field so that it is not displayed on the
form twice.
I have a form having some text boxes, radio buttons, and select boxes. I write custom validation methods which i added using validator.addmethod.
If user submitted this form keeping some or all fields empty then form should get submitted but if user enters data in text boxes then data should be alphabetic and should not contain special character and numbers.
I write validation code for some text boxes for which the custom validation code as I mentioned above is as follows.
$.validator.addMethod('specialchar', function (value) {
return /^[^a-zA-Z]$/.test(value);
}, 'First Name should not contain special characters.');
**Now actually when user submits form with empty fields then error messages of above custom validation method is displayed for those textboxes to which above method is assigned **
I think there is also problem in my regular expression which i can not able to spot.
If my regular expression is right then is there any other method to add regular expression in JQuery i.e. lookahed regular expression.
Please help me on these two problems guys
Thank You
Maybe something more like this:
/^[^a-zA-Z]{0,}$/