-
Notifications
You must be signed in to change notification settings - Fork 5
Put & Post Input development ramblings
On input detection, determine whether the enclosing 'tr' tag had a particular class associated to it. If the input was in a collection type object, the enclosing row would have a class of 'collection-(original/new-#)'. Continuing on the collection example, all of the elements of the collection would be determined and a value containing everything would be created. The name of this object would then be found. This name-value pair would be made into an object that was then be submitted to updateTextArea.
Since the text area is a stringified JS object, the text area would be parsed into an object, and then the object that was passed in would be used as a key and value for this object
( For example, dataObject would be the object passed in, and txtAreaObject would be the parsed text area object.
// Remove emtpy values from text area
if ( dataObject['value'] === '' ) {
delete txtAreaObj[dataObject['name']];
}
)
This works well enough if there is only a single level of depth for parameters. Once there are nested parameters, this scheme falls apart.
Now, when input is detected, the root node (div.content) is found, and things will work in a tree traversal type manner. A snapshot of the tree will be created, and this snap shot will then get stringified into the text area.
The new method has the side-effect that if any changes are made directly in the text area, those changes will be lost if an input field is modified. That isn't necessarily the case with the old method; if a property is added to a collection in the text area, and then a input field belonging to that collection is modified, the added property will be lost. If a simple name-value pair property is added to the text area, and changes are done in the input fields, that simple property should remain untouched.
In the old method, if something is added to the text area that then breaks the JSON format of the text area, then modifications to the input fields are no longer registered in the text area because the text area can no longer be parsed. With the new method, since the text area is refreshed every time input is done, this will not be a problem.