I have a registration form, I'm filling some form elements. Meanwhile if I click term and condition link. It'll redirect to that page. After come back same register page, there is all fields are empty. Again I start to fill up form from scratch.
So I need whatever I fill up as auto fill in form elements. That means my state values updated. How to possible in React JS?
There are multiple approaches to this problem.
Pass data to the new navigated page, and on completion of the action, you can pass back data to the registration form and have your form populated.
Store all data in a state, and update state on each form input entry. So, once all entries are made your state is updated with all values. The only constraint here is that, the DOM node shouldn't go out of scope or shouldn't disappear from the DOM tree.
Use redux to store all form values
I myself am not familiar with React, but this seems like a great tutorial on how to handle form in the ReactJS. His form seems to remember the previous input even after reload, also he generates the form dynamically, and he provides nice JSFiddle code on Fiddle code:this link.
Hope this has what you are looking for.
Related
in my react.js project I am using Ant design and I need to fill in my form in modal with values from state when the form is showed. Consider the following code sandbox: SANDBOX
Here we have modal with title field and value of title stored in state:
formfields:{
title: "Some Title Here"
}
So when the form is showed I need the title field filled with Some Title Here. The main problem is that I dont want to place value of <Input> as this.state.formfields.title, so I dont want the state to update on every keystroke. Actually I need only take the data from state when the form is showed and update the state only when the form is submitted. No state updates should occur when the user inputs data into form fields. I checked some kind of THIS and THIS but it did not seem to work (maybe because of modal, anyway I dont know whether it is correct to do this like that).
Any ideas would be welcome. Thank you.
Maybe you should set the value as a state value and set the formfields.title one when the form is submitted. If I understood your problem correctly, I mean...
I have a hidden field that stores some Ids of items to be updated when a button is clicked on the page. This is working fine. However, if the user clicks the Update button, then waits for page to reload, and then refreshes the page manually (using browser Refresh button), the data is resubmitted and creates duplicate data in the database.
Is there a way to clear the hidden field in the Postback data so that if the user does refresh the page manually, the hidden field will be empty and no updates to the database will be made?
So far, I have tried to manually update the ViewState using the code below after the database is updated.
ViewState["hdnBulkIds"] = "";
I have also tried to exclude the hidden field from the ViewState and manually clear it using jQuery on page load.
$( document ).ready(function() {
$('#<%= hdnBulkIds.ClientID %>').val("");
});
In both cases, I cannot seem to update the data "instance" that is sent to server on manual page refresh so the hidden field retains its original values from original button click.
I guess the question can be simplified to this: Is there a way to update the Postback data directly using ViewState or some other method to clear the hidden field?
This is a big issue with webforms in general and a big reason you should consider jumping ship to MVC. There may be an elegant way to handle this through webforms, but I'm not aware of any.
Once the user submits a form the browser "remembers" that submission and the refresh will re-submit it. There is nothing you can do about that, you have to detect a second submission through other means.
Your best/most true solution is to do a redirect after you get all of your data, and use your query parameters to re-build the page in the state it needs to be in. Then when the user refreshes the screen it will resubmit the redirect instead of the form submission.
Page.Redirect() or something along those lines is the function that lets you do a redirect. Trouble is, a page redirect will erase all state webforms was maintaining about the page, you have to rebuild all of it.
You also might be able to implement some sort of "CSRF" token style system. Generate a random number and store it in the user session on page load. When the user posts back, invalidate that number somehow. That way, if they post-back again with the number you can cancel the request.
That's a hackey way of going about things, doing a redirect is the "tried tested" method to my knowledge.
Another option is if the postback edits a value, check for duplicates or if the value is edited and if there are duplicates don't let the user double-submit.
I have an entity form (Entity A) which contains an subgrid to display linked records of another entity (Entity B), where multiple B records link to one A record.
Records of entity B are linked to entity A by clicking the '+' icon on the subgrid, filling out an quick create form for entity B and saving. After the save, the newly created record B shows up in the subgrid on the form of record A: all as expected.
When filling in the quick create form for entity B, a field containing an amount needs to be filled. After saving, a server side plugin fetches all records of entity B linked to the specific record of entity A, calculates the sum of all their amounts and fills the total amount in a field on the form of the record of entity A. This also works as expected, the newly calculated value is stored in the database. The problem is that the field that displays the total amount on form A does not refresh. It keeps on displaying the same amount it did when the form was loaded and only updates after a full page refresh. The value though, is updated every time a new record of entity B gets linked. The value on A only shows it's 'new' value when the page is refreshed.
The problem is that the users link 10+ records of B in a row, without refreshing. We get the request to make the field refresh automatically quite a lot, but i have no idea if this can be done, so: Is it possible to refresh (/re-render) a field on the form of entity A on the on save event of entity B? I presume this has to be done in javascript, since it is the client side representation of the fields value and the field value is already correctly stored in the database.
Thanks!
Using JavaScript, there is a grid refresh event you can subscribe to. From there you have a couple options.
In the refresh event you could trigger a rest call to retrieve the value from the server, and then update the value on the form. I'd also disable submit for the field as well, since you don't want the client updating it.
Or- Call save explicitly. You'd either have to ensure the form is valid or change all required fields to no longer be required to allow the save to happen. The save event will return the updated value from the database and automatically update the form.
If you've never made a rest call before, the first option is probably harder, but IMHO, it is the better option.
If helps. it can be done in C#. You can make plugin using the logic you described here.
That plugin would be registered using Plugin Registration Tool. you would have to add two steps for Entity B. First one would have Create message, and the second one Update. For the second step you would select just the amount filed update, so it is triggered only when that filed is updated.
It can also be done using Rollup Fields. They can be updated on click, but also have automatic update on every 12 hours, if that is frequent enough for you.
I don't have an idea how to do it using JavaScript, but i am new in CRM, so someone else might appear with that type of solution, I would also be glad to read it.
The easiest solution I can think of would be to poll the value by adding a new handler to entity A's form OnLoad event.
The code would then employ setTimeout to constantly read the value of the field from the REST API, compare the content of the field, and if it's changed it would invoke Xrm.Page.data.refresh to asynchronously reload the form without a full page reload.
Another (IMHO better) option: upgrade to a more recent version. Starting in 2015 Update 1, subgrids have OnLoad event too: you just need to handle that, invoking Xrm.Page.data.refresh without the weight of repeatedly pinging the server.
I am moving from 1 page to other in html, passing the form elements and their values.
In creating the values I show/hide certain elements based on the need.
Now when on next page I click EDIT, I come back to this page but the view is the default view.
How can I modify the view using a jQuery/javascript from default to something based on the values saved, on form re-loading for edit?
if(jQuery('#UPLOADFILE').prop('checked') == true) {
jQuery('.FILEVIEW').show();
jQuery('.OTHERVIEW').hide();
}
Could you please give me a js example how to activate the above code. Everytime I re-load the page this piece of code doesn't execute, although #UPLOADFILE is checked.
Thanks in advance.
You know, instead of using JQuery, you can always save it to a database and then edit it to update the values. Seeing that you're trying to save something anyways(after you edit it, in my understanding), why not save what you entered and then edit it if you want to? Simplifies things a lot, imo. Just saying.
I would go with #Lloyd Francis answer but in case you don't want to do DB save and fetch then you have following options on client side.
Save the state in
Cookies
Pass the date in URL between pages ( not recommended )
Local Storage http://www.w3schools.com/html/html5_webstorage.asp
In the document ready event handle the logic appropriately.
I have a situation where i have to modify a form (to dynamically add a table) via jquery after it's been rendered / created.
The problem is that when the form is submitted, and redisplayed because of errors or validation issues, I don't know of a good way to save and redisplay the data they've entered into the fields I've created dynamically.
Any suggestions would be appreciated.
You probably want to use something like jQuery Populate.
Dynamically added data don't differ from the static added ones. You have to use 'validate()' method to prevent submitting and rendering the html-code with errors, in this case user will see the dynamically added data.