0

Similar to jQuery how to load some json records into a form fields?, I'm having a rather complex form where fields interact with each other, requiring recalculations (some complex mathematics) as well as disabling fields upon certain conditions. Class at server which may output JSON or similar.

The calc-request is fired by jquery on any field-onchange, and should pick up the class-response and act accordingly. About acting upon the ajax-response:

  • Can the response be formatted so the fields are updated/faded without iterating the JSON-result?

  • Please provide an example of a state-of-the-art json-response for such functionality.

I'm trying not to reinvent the wheel but keen to go as vanilla as possible, plugins tend to break.

EDIT:

In essence:

$.ajax({
  url: "theCalcClass.php",
  context: document.body
  }).done(function() { 
    //use the json data to update fields w/o foreach...
  });
2
  • Why exactly you don't want to iterate the JSON response? Commented May 10, 2012 at 22:08
  • It itches. One tier too much. Commented May 10, 2012 at 22:12

3 Answers 3

1

I'm not sure I understand your question. If you are looking for a built-in one-liner like form.repopulateWith(json), it doesn't exist. Your options are:

  1. Looping the JSON and repopulating each field, or

  2. Setting the field values one by one without looping.

Any other solution (like a plugin) will have to use one of these approaches, there is no other way.

Sign up to request clarification or add additional context in comments.

3 Comments

I belive you understand my question. I more or less want to bind the JSON (object) to the DOM.
Yes, but there's no "vanilla" way to do that. Maybe Backbone.js (suggested by @Amadan) can do that, but it's a whole framework. JS and web browsers do not provide that out of the box.
Ok, thank you. Backbone however, seems too clever for the purpose.
1

Not 100% sure what you mean, but I believe a MVC framework like Backbone.js might help you.

Comments

0

There is something that does exactly that (including array of subobjects handling): https://github.com/corinis/jsForm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.