How to run validation on a slice of a redux-form FieldArray state - redux-form

I am running something very similar to the example here:
http://redux-form.com/6.0.5/examples/fieldArrays/
Say I want to add a list of members and a list of hobbies under each member, like in the example above.
What is different from the example above is, I want to also be able to validate each member, before I am able to add additional members or hobbies for that member.
Similarly, I also want to be able to validate each hobby, before I can add another hobby.
In other words, I want to be able to treat each entry in the FieldArray as a form and each add button as a submit function for that form.
I would have a validateMember and validateHobby validation functions that I would run against the respective FieldArray entries.
I am not aware of any feature of redux-form that allows running synchronous validation on a subset of the form's state. Alternatively, I also cannot treat everything as a form as then I would lose all the nesting (i.e. which hobby belongs to each address).
Any ideas and suggestions are greatly appreciated!

Related

Dialogflow CX: $session.params.list as a separate entity type

Let's say I have a dynamic list of items which I upload from a webhook at a certain step of a scenario. This list is not a list of some type of pre-defined entities, this is just a list of something.
So,
$session.params.items = ["item_1", "item_2"]
Now, at the next step user can either choose one of the options provided in this list or make something else. It seems that the best way to check whether the next user query has something to do with our list of items, I need to declare a non-required parameter. But if I do this way, they necessarily require an entity type.
So, the question is:
Is is possible to use any list or dict from session parameters as an entity type?
What is the best way to implement checking whether user query falls into one of the session variables like list taking into account that user query may as well go to other intent and so on. I supposed the best way is to have routes for filling in unnecessary parameters and for intents, but still I can't do the first part.

I would like to define a component as optionally required (based on another field's value)

I built two custom components using built-in CQ components. The components' JSP's, along with some custom javascript, have a line like below in order to leverage the built-in components (and their formatting, labels, etc.).
<cq:include path="." resourceType="foundation/components/form/dropdown" />
I have one each of my custom dropdown components on a form. I can mark field A and field B as both being required in their respective components' editor dialog. I can provide required messages so that when either field is blank and the form is submitted, I get a message that the fields are required (with my custom messages). However, what I really want to do is hide or disable field B based on the value supplied in field A. I'm handling this manually via jQuery. However, this of course presents a problem on validation. I want field B to be NOT required when it is hidden/disabled and for it to be required when it is enabled/visible. Since the showing/hiding is done client-side, the server-side validation has know knowledge of the change and still expect a value to be provided for field B.
I'm been trying to poke around in the CQ Widgets API to find if there is something I can do on the client side to set/unset the required property so that when the form gets posted it is handled correctly. I'm guessing that there isn't since the validation seems to be happening on post instead of client-side.
Any ideas/thoughts/options?
It turns out that the link from my comment gave me the idea that I can have custom server-side validation for my form, I just wasn't sure how to connect it to the field. It turns out that all I had to do was create a servervalidation.jsp file in my "B" component. CQ will see the servervalidation.jsp and automatically invoke it for my custom component.
I was then able to examine the submitted value of field "A" (by getting the parameter from the request object) and doing some other custom logic for my needs.
I was then able to optionally do this:
FieldDescription field = FieldHelper.getConstraintFieldDescription(slingRequest);
FieldHelper.checkRequired(slingRequest, field);

skip all ModelForm validation conditionally but include it all otherwise

I have a form that has a selector at the top where a user can select none, or choose a couple options where the validation varies depending on the selection.
If they select none, then it needs to save the model ignoring all the fields and just putting in "None" for the one option. If they select one of the others, then it needs to preform validation on all the other fields.
The thing is, the only way for me to get it to save when "None" is selected, is if I set blank=True on all the fields for the model. So I basically have to turn off all the validation.
But then when they select something, I override the clear method and have to do all the validation manually...
Is there any way for me to use all the built in validation based on the option? In other frameworks I've used, there's an array full of rules, and I can just modify that based on whatever and then run the rules automatically off that array.
Is there a method before the clean, clean_fieldname, and any other validation where I can grab the one selected option, and modify the rules for everything else based on it before it does the build in validation?
I just can't seem to figure out how to use the validation in a versatile way in Django. It seems that if I'm not using them in one specific scenario, it falls down to having to do it all manually. I am fairly new to it, so I'm likely missing something.
Thanks

Expression Engine Channels in CodeIgniter?

I need to build an application wherein the admin must be able to define forms for data entry. The data to be entered is unknown to me. But the system will need to be able to support all the possible form fields (minus hidden fields, I suppose). So text areas, text fields, radios (with ability to specify what the options are), checkboxes, etc. Also, it needs to be able to support line item entries (similar to EE’s Matrix plugin).
Obviously, I don’t want to try to build this from the ground up. Are there any libraries I can use in CI to make life easier for me?
If none exist, what are some database design patterns I should consider for such a problem?
The best database-design for this is the Entity-Attribute-Value Model. For use with a FORM, essentially your form is the ENTITY, the Attribute will have a type (used for deciding how input will be captured, and data interpreted). Make sure that you index properly.
Remember that you'll only need to data to change the form, don't read from this model everytime you need to show a form. Store a flat file (.json is handy) of the finished form and read that when displaying the form.

How to force Wicket "onchange" AJAX events to be triggered if fields fail validation conditions

The specific case I've got in mind is as follows: an AjaxFormComponentUpdatingBehavior("onchange") is added to a TextField in a form. The behavior verifies the text for certain conditions (either the model object or the form component model, doesn't matter), based on which it might display a message (or hide it, if it has already been shown).
The problem is, there are also validators added to the TextField. One of the possible (and likely) scenarios consists of the user typing in, first, a value that causes the message to be displayed by the AJAX request. If, then, he/she types in a value that doesn't pass validation, the message should disappear, but it does not.
Apparently, either the onUpdate() method for the AJAX behavior is not called at all, or I am failing in my attempts to insert a check for non-validated entries (I have tried to test for both null values and empty strings, to no avail; I have no idea what exactly Wicket's validators do to models when data is invalid).
I am wondering if someone who actually understands validators (or AJAX, actually) has any ideas on where the problem could be.
I can post edit and post code if someone tells me this is not a general issue tying validators and AJAX, but most likely a programming mistake. I still believe the former and thus I'll refrain from posting code sections, in order to keep the discussion on an API/theoretical frame.
Thanks.
When using an AjaxFormComponentUpdatingBehavior, if any of the IValidators fail their validation, onError() will be called instead of onUpdate(). Wicket will effectively prevent invalid user input from reaching the IModels in your components, so the component's ModelObject will not be changed at all. The invalid input will probably remain available by means of getInput()/getConvertedInput() (not sure if it will in an AJAX scenario, it sure is in a traditional form submission).
However, take into account that IFormValidators are not executed when using this mechanism. If you've got any, you might be interested in overriding getUpdateModel() so that AjaxFormComponentUpdatingBehavior will not bring maybe-invalid user input into your IModels, and set modelobjects manually when you're certain user input is valid.
Regarding your specific case, you could perform all the required logic in onError() (or rely on Models that will grab data from somewhere else), and just add the components that need refreshing to the AjaxRequestTarget. This is probably what's missing in your scenario.

Resources