Skip to content

Added ability to pass an object to formParams to (re)populate a form.#90

Merged
justinbmeyer merged 3 commits intojupiterjs:masterfrom
ralphholzmann:master
Nov 25, 2011
Merged

Added ability to pass an object to formParams to (re)populate a form.#90
justinbmeyer merged 3 commits intojupiterjs:masterfrom
ralphholzmann:master

Conversation

@ralphholzmann
Copy link

Pretty straight forward -- thoughts?

Ralph Holzmann added 2 commits November 15, 2011 15:32
…a form. In other words, formParams is now a getter and a setter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love have some low level populate functionality. Was running into that again today (specifically populating Controllers that expose .val() method) and with Model + Observe it would be really easy to tie forms and models both ways. I am not sure if it takes care of nested params at the moment though. Wouldn't it return

params['test[key]']

instead of

params.test.key

?

var name = $(this).attr("name"), parts = name.match(keyBreaker),
    value = params;
for(var i = 0; i < parts.length; i++) {
    if(value[parts[i]]) {
        value = value[parts[i]];
    } else {
        return '';
    }
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Names using bracket notation, e.g. foo[] aren't handled. I'll add that to my next commit on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. I can add some tests if you want.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has it's if ( value ) condition and it can lead to errors. For example if you want to switch current edited item and it's field is empty then if(value) is false and last edited value stays.
This condition isn't necessary .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@selecton Good catch. I assume if ( value !== undefined) would be the proper test. I'll make the changes now.

justinbmeyer added a commit that referenced this pull request Nov 25, 2011
Added ability to pass an object to formParams to (re)populate a form.
@justinbmeyer justinbmeyer merged commit 856c12d into jupiterjs:master Nov 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants