How to add custom validation in plugin configuration? - validation

I have a text field in the configuration section of my plugin. The expected values are numbers separated by ',' eg 1,5,10. User should not be able to set this value to 0. How I can validate the field?

You could hook into the save-event with a subscriber docs
And there you could access the request data and validate it on your own.
My question would by why do you want to do that?
What do the numbers stand for?

Related

Make parameter input required in CloudFormation template

I have a template for AWS Cloud Formation. In this template I have set several parameters.
Now, what I would like to do is to leave a parameter field empty but allow the user to select
a specific parameter for example a security group. Now what I would like to do is that if
a user does not select anything (field stays empty) I want it to give an error message saying
field required when you want to proceed and prevent the user from proceeding, as it happens when you do not enter a stack name (see screenshot below).
How do I do this for any parameter in a cloud formation template??? I have searched around but do not find anything
regarding validation of user input …
I know I could set a default for everything, but I do not want to set a default and specifically force
a user to make a selection in this case …
Please see this thread:
https://forums.aws.amazon.com/thread.jspa?threadID=230829
Suggested solution: simply use regular expressions in AllowedPattern.
For e.g. to have a non blank value:
"AllowedPattern" : ".+"
If you want the parameter to be alpha numeric:
"AllowedPattern" : "[a-zA-Z0-9]+"
To match an exact word:
"AllowedPattern" : "^my_matched_word$"

Laravel validation; human names for array fields

In Laravel form validation you can do this: file_description.* to validate each item of an array according to a set of rules. The problem is, the system automatically returns "file_description.1 is required" as an error message if the field is required and not filled in.
More on that here: https://ericlbarnes.com/2015/04/04/laravel-array-validation/
Now, I'm not a complex man, I just want the field to say "File Description 1 is required". I am aware you can set messages but a) my input arrays are dynamically generated by jquery (click to add more type scenario) so I'd have to use a loop like in the above example b) I feel like there must be a better way.
Is there a way to either extend the core validation system to simply return a humanized name for the array field as Laravel does with regular fields, or is there an option I missed in the docs that allows for this? I'd rather not get involved with doing some regex type search to fix this.

validation.xml change mask value on condition

I am working on struts server side validation(version 1.2). I have used validwhen several times. I have 2 textboxes that submit to server. text1(value comes here from a drop down selection) can have name or id. text 2 holds its value. I have to write validation on text2. Is there a way where i can change mask var-value in validwhen ? i.e if text1 value is name then text2's mask should be a regex for name(alphanumeric and space). if text1 value is id then text2's mask should be a regex for id(only numbers). Is there a way this can be achieved? I don't think we can write 2 different validation on same field.
thanks,
IMO validation like that belongs on the Java side.
You can either wrap it up in a custom validator if it will be used across the app, or as part of the form's validation method, where you could also combine it with standard XML validation.

Changing NameFormat in SAML 2.0

We are using SAML 2.0. We are supposed to integrate with an external client.
The customer is requesting use to change the following
NameFormat="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" instead of NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
Can we do that. If yes, how?
NameFormat is an attribute of Attribute element under AttributeStatement element of SAML assertion. SAML Core Specification mentions three attribute name format identifiers:
urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified
urn:oasis:names:tc:SAML:2.0:attrname-format:uri
urn:oasis:names:tc:SAML:2.0:attrname-format:basic
Now, urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress is a name ID format identifier. It is used as the value of the attribute Format of either NameID, NameIDPolicy, or Issuer element.
When you mentioned that you want to replace urn:oasis:names:tc:SAML:2.0:attrname-format:basic with urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress, it puzzles me because they are used for different purposes.
Perhaps you can clarify your question?
In your AuthnRequest, you should have something like:
<samlp:NameIDPolicy xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
SPNameQualifier="xxx"
AllowCreate="true"
/>
Change the format in there e.g. the format above is "transient".

Organize validation messages in Struts2 validation(XML)

I am trying to do validations in struts 2 for my current project. I have to group my validation messages. For Eg: If there are 3 fields that are empty and there are 3 other fields whose format is not right, I need to get a msg like
"The following fields are required: field1, field2, field3
The format of the following fields are invalid: field4, field5, field6"
I tried providing a param to fieldError.
Eg:
< s : fielderror >
< s : param value="%{requiredstring}"/>
< / s : fielderror>
According to me this is like specifying "show all errors whose validator type is requiredstring". Please correct me if I am wrong.
But this will display the message "The following fields are required" each time for every field that is empty. I want it displayed only once.
Is there a way to do this cleanly in stuts2 using validation through xml? I donot want to do all the validations in a validate method.
Thanks
You are wrong; I have no idea why you thought that'd work, the docs don't imply that's possible.
Field errors are just that--errors for a specific field. If you need to group errors by arbitrary criteria, like the validation type, you'll need to implement that yourself.
There are a number of ways to do this, including writing a custom validation interceptor, providing validators that group errors in a different way, or simply gathering the appropriate messages in an action or validation method.
You could gather errors based on the message content, but IMO that would be brittle. If this is a cross-application issue, you're better off doing it a different way.
All that said, by presenting error messages in an order not necessarily reflective of the form, you're pushing more cognitive overhead onto the user: I don't want to see groups of messages telling me which fields share the same error, I want to see what's wrong with each field, in the same order the fields are presented on the form, preferably near the form field itself.

Resources