Why does Ant Design form validation not work when more than one useForm is in the same component? - forms

I've found that antd's form validation does not always work if I create two form instances by calling useForm() twice in the same scope. This codesandbox demonstrates the issue. To reproduce:
Without filling in the field, click Next. You will see a validation error.
Fill in a value and click Next. You will go to step 2.
Without filling in the field, click Next. You will go to step 3, but you should've gotten a validation error.
Click Back to return to step 2.
Click Next. Now, it gives a validation error.
Fill in the field and click Next.
Click Back to return to step 2. Note that the field has retained its value.
Click Back to return to step 1. Note that the field will be empty. (Why? This may be related to the issue.)
Click Next. No validation error.
From this, I am guessing that the Form component doesn't "know" about the fields in those cases where it fails to validate them. When we return to step 1 and the field is empty, this is a sign that the Form lost track of that field, which is proven when it fails to validate it when you click Next, which had worked originally.
So, is this a bug, a feature, or am I doing something wrong?

you only need to use one Form.useForm();
for the "step2Form" form you replace only using "step1Form"

Related

ms-access 2003 form data entry stopped working

I have a form with a subform that at one point allowed for data to be modified. It now gives an audible "bing" when I try to change a field. My save cmd button now displays the error "The command or action 'SaveRecord' isn't available now." My form on the switchboard is set to Command: Open in Edit Mode, both the Form and subForm are set to Data Entry "Yes" on the Data tab. What am I missing that would cause the fields to not allow update adn the save command to no longer work?
It was working before?
I had a similar misterious problem with textbox zoom that a one point in time started generating an error, only in one form.
The solution was to create a new blank form and copy / paste all controls from the defective to the new blank one, same operation for the code in the VBA and everything was back to normal.
You can try do do this and , if the problem persist, then is something in your code or in the form properties. Hope this will help

How to enforce wicket to validate disabled fields on the page right before onsubmit call

if we use setEnabled(false) say on text input type it disables and not take part in form validation so how can i enoforce this right before onsubmit
As a general rule browsers do not submit the value of disabled fields at all. (As mandated by the HTML standard)
It's important to see that because of the browser sending no data, the problem is framework-neutral. The solution is also independent of your framework:
Double-fielding: each text field that you intend to disable should have a "shadow" hidden field where its value is copied.
In the Javascript function that does the submitting you can re-enable the fields for the time of submit only. I haven't tried this option yet so I'm not sure if this is a good idea or indeed if it works (it should though).
A separate, Wicket-specific issue is that even if the browser submits the values, any Wicket component which has setEnabled(false) called will refuse to process them. So you'll have to extend double-fielding into your Wicket component structure as well, which won't look very nice.
So it's doable but you should know that users will not expect disabled fields to be submitted and you're likely to cause confusion by changing the standard behaviour of form inputs. You might want to think about redesigning your UI as an alternative option.
If the component is disabled it won't have any input to be validated. I'll assume from now on that you want to execute a FormValidator which involves some other components' user input and this disabled TextField's model object.
Unless you return the disabled TextField in FormValidator.getDependentFormComponents(), the FormValidator will continue to execute. Take into account that FormComponent.getConvertedInput() won't return anything, because there's no input. You can get the Modelobject instead by using FormComponent.getValue().

Using multiple forms or multiple submit buttons, what's the difference?

Basically, what pros/cons are there to using multiple forms in the same web page vs one form with multiple submit buttons? Any difference at?
Ah? Multiple submit buttons on a single form will all submit the entire form when pressed... there's really no advantage to having multiples, unless you're overriding how the submit process works so each button only submits it's own area. In this case they'd probably not even by submit buttons, but just buttons with sum JS code to handle submission.
Multiple forms are discrete spaces of data collection, each can have it's own submit button... but only one of them can be sent at a time (and depending on the browser you may loose what's in the other forms).
Neither approach is particularly good from a user interface perspective since it'll be confusing.
The real question is, what are you trying to do that prompts you to ask this?
The two behave differently and there are good reasons to choose one over the other.
Multiple Forms on a page allow you to send data to two different locations. A common example is to have an input form as the main focus of a page going to one location, and a search form that appears as part of the generic header/footer. These both go to separate locations and submit only the HTML form elements within their appropriate <form/>
Multiple submit buttons offer you the ability to give different purpose to a submitted set of form elements. E.g. One form may have a bunch of submit buttons all with name attributes, meaning you can add conditional logic on the server side to say: "Continue", go " Back" or even "Save for later". All reference only the form elements within it's parent tag.
Two side notes are: 1) You can't nest forms. 2) JavaScript can change this default behaviour if you wanted it to. :)
Edit: with reference to a comment you made, if you wanted to do without JavaScript (a wise choice while it's not needed), you could do some careful thinking and keep POSTing the form to itself. Each time checking which form button has been clicked (top tip, give them all the same name and you can just switch case through it) and do whatever you need to do, including performing validation. E.g: When they hit "add media", you'd save the media uploaded and return a reference of it to the screen as a hidden input. The user can then continue to add things to the other boxes and when complete, hit your save button, at which point you do all the main saving work and make sure you tie the uploaded file to it as well.
You effectively keep adding stuff to their screen until they hit the save and then you perform a save method and redirect to a thank you page (or whatever logic suits your scenario). :)
All fields in a form are sent when one of their submit button is clicked. It's for you to see if you need all fields or not.

step by step problem with validation on "back" button

I have a 3 steps forms where I bind for each step on a ViewModel that has DataAnnotation. Everything works fine except that when I click on my "previous" button, the validation gets called and, if there's missing values, the user has to fill all required fields. If I go with an action link, then the data won't be persisted. What I'm looking for here is a way to save my values without calling the validation. I also consider using cookies but I don't think that it's the best way of doing it.
Any ideas or suggestions?
I use separate models for each step of my wizard pages. I also make sure that the previous clicks do not hit ModelState.IsValid which is what triggers the validation check.
I store the results of each step using session state stored in SQL Server. You can also use hidden variables but I didn't like that solution.
Add a comment if you need more detail or show some code for us to see.
Ok after lots of searching I found out a solution for having a Wizard like multiple forms with previous and next buttons that won't call the client validation from Data Annotation and MicrosoftMvcValidation.js. I found this post : jQuery Validation plugin: disable validation for specified submit buttons witch simply add a class to the submit button but it was not working for me so I look again and found this one : http://forums.asp.net/p/1622628/4165648.aspx witch has a solution working for me in javascript : document.getElementById("someButton").disableValidation = true; I would prefer a jQuery solution so I could do something with the class attribute of my buttons but it's working for today and I've spent too mutch time on this.
Hope it helps some else who's trying to do a "Cancel" button or a Wizard like forms in MVC2 and want's to post the form to the controller so he needs to clear the validation.

Stop form from open when no records

I have a data entry form that when it closes opens another form for further updating the just newly entered data. However, at times no further update is necessary. How can I suppress the 2nd form from opening when there is no need for further update? Presently the form opens even when there are no recordsets present. (need a similar Event like for the report "On No Data")
Have a bit field such as a checkbox with default set to true open second form. Uncheck it to avoid the system from opening the next form. You will need to handle this in your code and check if that check box is checked or not.
Of course we will need more details such as why you are currently opening this second form...in addition, cant you check if any changes were made and if they were then open that second form else dont? Also what lang ?
Without knowing more about what you're working on, I'd say you would have to modify the process that shuts down the first form to check if the second form is needed. In .NET, for example, you could add code to the OnClosing event for a WinForm to check. If it's needed, open it as normal, if not then don't.
Subject: Tool Kits. Tool Kits consist of 1 or more tools. If tools already exist, no need for 2nd form to pop up. If tools are new, I need to fill in one of the 3 fields in the drop down listing. I like the idea of adding code to the OnClosing event, but do not understand what you mean by WinForm.