Angular Form Validation Across Several States/Views - javascript

Bit of a broad question however I'm sure someone can offer me some sound advice!
I am currently developing a form which is presented to a user over several views/states. A user fills out the first section, clicks 'next', state changes and the next part of the form appears etc...
When the user goes to submit the form on the last state and they have made some mistakes in the first or second state, would it be possible to have them redirected to the sate in which they made the error, and focus on that field?
I ask simply because I will have to implement this at some point, and do not want to go forward as planned in case this is not possible using several different states to present the form.
Each state shares the same object using a service, which is used to hold the inputted data.
Any advice would be much appreciated as always.

Related

Triggering a re-fetch when coming back from a dialog modal react

I have an add contact Modal and an add company Modal. When the user wants to add a contact they click the corresponding button which opens said Modal. Typically, they would fill out the information needed on this form. One of them being a Company they belong to. If the company does not exist in the system, they then have an add company button which when pressed opens another Modal on top of the contact one.
Again, the user enters the information for the company and once done, would tap save. This would then trigger a fetch which POSTS the information to my Spring Boot backend which in turn sends back a JSON object version of the company which has come from the database.
I then check it and if it comes back valid, it sets out an alert telling the user it was successful and closes the company Modal.
At this point, the user should be able to type the company name into the contact company autocomplete and find the company they've added.
However, at this point, that is not happening. The re-fetch is not triggered at all despite me thinking that when the Contact Modal is re-rendered it would trigger the re-fetch.
I've tried clearing the contactList within the return() function but this causes a Too many re-renders error.
My question is, how would I trigger a re-fetch from within the contact list once it has returned from the company modal?
My initial thought would be to not have more than one modal open at the same time. Feel free to disagree but that doesn't seem like that's how modals are intended to work. As an alternative, you could have an "Other" option and have a set of text fields conditionally appear. Upon completing the form, have a boolean variable (or however you want to do it) be passed into your backend that kicks of the business logic that creates a new company before adding the contact. Or add all that logic to your add contact SQL procedure to avoid making (a risky) two db calls for one action.
Refetch Problem
Without looking at your code, it's possible that if you're using the useEffect hook, you aren't passing any dependencies to "listen" for certain variables that have been changed. After the data comes back from that POST call, you should add code that updates the array populating the select company dropdown field (eg .then() callback)--assuming it is a dropdown and an array. This change in state should re-render the component but, for a better user experience, you may want to do it in a way that it doesn't blank out the rest of your fields.
You are probably using useEffect which makes the loop.
Try to connect refetch with an event - click or submit, within try/catch - via 2 way binding eventHandler prop that calls praticular function.
Also you can change the state, and refectch the results after the new loading of the page. Hope it helps, even as a hint!

Reload partial and retain form values

When purchasing a course, the user can enter 1 or more students to register for the course. By default there is only one entry but the user can use a dropdown to select more and then the form will update to show more.
I am accomplishing this by triggering an event when the user changes the dropdown value that uses ajax to call an action which returns a partial with the appropriate number of entries and then I just replace the existing div with the new one.
My question is whether there is a way to implement this so that it's kind of like "refreshing" the page where the form remembers and automatically refills in he values the user already entered just like if you were to refresh the entire webpage. Is there a way to do this, or will I need to pass in the existing values into the action in my ajax call and have the partial set them?
A secondary question I just thought of (and perhaps this should be in another post but I will go ahead and put it here for now) is whether I should be concerned about any weird behavior with validation when doing it this way? (I'm using stock, built in validation with annotations).

Reason for update/delete field in django

I am trying to create a simple app that forces the user to enter a reason for update or delete when they are editing an existing model through a form. I have created the model and the associated form. The part of the model that asks for the update summary works fine, but when it appears, it obviously always has the last update that was entered for the model as part of the update view. Is there some way I can "blank out" the update summary every time? I am also trying to create a history of each form and I'm still in the early stages of that. I see that there are several options available, but I'm still exploring those. I'm a newbie, so any help you can offer is appreciated!
Here is a copy of my current model:
class Pizza(models.Model):
pizza_name = models.CharField(max_length=264,unique=True)
customer = models.TextField(max_length=264,unique=True)
update_summary = models.TextField(max_length=264,unique=True,null=True)
I have explored possible using Javascript to blank out the form in the update view but can't seem to get that to work. I have also considered trying to override the form in the form view, but can't seem to get that to work either. I ultimately want the update view to show the pizza_name every time as well as the customer view, but I want the update_summary to be blank every time. I intend to store every update summary on a separate history record to be viewed in a history view somewhere but am working to figure out how to best approach this as well.
Thanks in advance for your help!

Can I keep fields in a form populated even if I move to a different page and then back?

I am currently looking at creating a form using HTML, CSS and a bit of JavaScript. I was wondering though if anyone had any ideas how I could keep all the fields populated?
I want to be able to fill in a form and click 'Next' which will go to a different page with a different form. But if the user presses the 'Back' button to edit some information on the previous page for example, how would I keep all the fields populates?
Bit stumped on this, so any suggestions would be appreciated :)
You may use localStorage or cookies for that purpose to store content of the page on the client' side.
See https://stackoverflow.com/a/27273657/696034 for an example; in you case, you call save() when receiving location change event, and load() on the page' initialization.

Restricting The Viewing of Forms Per User

Please could someone assist with the following:
I'm trying to restrict the viewing of forms using bootstrap and Meteor. In other words, user A logs in and creates a simple (or 2, or 3...) form using a modal which then displays in the html on a panel. How do I ensure that when user B logs in, he only sees his particular forms and not "user A's" forms?
I haven't included any code as I haven't started working on this problem as yet.
Thank you.
That's something you need to deal with using your publications/subscriptions. See here and here for learning ressources.
Basically, what should happen is that when user A creates a form (or any object), you store it into a collection along with the user id (Meteor.userId()). You subscribe to a publication in your page where you send only the items belonging to the current user Id.
That should solve your problem, and make you ready for all the similar (and common) cases where you need to disclose selected information only, depending on the context or the user. Moreover, it means that your users will be able to find back the items they left in their previous sessions.

Categories

Resources