0

under Plone4/Zope3, I have a form to add a new object.

I'd like to add a button after the first field, to do the following : - the user enters the value for the first field - he presses this new button - and the server will try to guess the remaining field based on the first field and an external database. - the user will then have to check if all fields are OK and then submit the form.

I am not a zope expert, and spent some time trying to figure out how to do this.

Is creating a subform a good idea ?

If not, I could add a new button to the form : I tried something like @button.buttonAndHandler(_(u'Essai')) def essai(self, action): print "button essai"

but then I have the following issues : - how to render the button after the first field and not at the bottom ? - how to update the remaining fields without submitting the form ? - how to keep the "add" and "cancel" button that disappeared when I added this essai button.

any hints ? Thx

Pixou
  • 1,719
  • 13
  • 23

1 Answers1

0

I suggest to use javascript to solve this. With jquery you can include an extra button directly behind your first field (http://api.jquery.com/after). In the button action ask a browser view for the search results in json (http://docs.python.org/library/json.html) an fill up the other form fields, like:

jq('my-button').click(function(event) {
    event.preventDefault();
    var first_field= jq('#first-field-id').val();
    jq.getJSON('/@@my-browser-view?value=' + value, function(result) {
        jq('#other-field-id').val(result.val_for_other_field);
        ...
    });
});
j23d
  • 48
  • 3