Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send form and form_state to variables to form generation functions #119

Closed
signalpoint opened this issue Aug 3, 2013 · 0 comments
Closed

Comments

@signalpoint
Copy link
Owner

Right now when a developer creates a form, they do so like this:

/**
 * Define the form.
 */
function my_module_say_hello_form() {
  var form = {
    'elements':{
      'name':{
        'type':'textfield',
        'title':'Your name',
        'required':true,
      },
      'submit':{
        'type':'submit',
        'value':'Say Hello To Me',
      },
    },
  };
  return form;
}

Instead, we need the function to take in the form and form_state (just like Drupal!), that way developers will modify the form and return the form, not create the form and return it. This will be the correct code to use:

/**
 * Define the form.
 */
function my_module_say_hello_form(form, form_state) {
  form.elements.name = {
    type:'textfield',
    title:'Your name',
    required:true,
  };
  form.elements.submit = {
    type:'submit',
    value:'Say Hello To Me',
  };
  return form;
}

We need to do this so default values like form.validate and form.submit will already be available when a developer is building a form. See https://api.drupal.org/api/drupal/modules%21system%21system.module/function/system_settings_form/7 for an example of why DG's implementation of system_settings_form() needs the form.submit set first.

signalpoint added a commit that referenced this issue Aug 5, 2013
…ing of the form id from drupalgap_get_form(). Changed drupalgap_form_load() to make a call to drupalgap_form_defaults() instead of trying to set the defaults itself, also changed it to pass the form and form state along to the form's builder function. Changed _drupalgap_form_submit() to iterate over the new validate and submit arrays instead of calling *_validate and *_submit handlers.
signalpoint added a commit that referenced this issue Aug 5, 2013
…lary(), taxonomy_form_term(), user_login(), user_register(), user_profile_form() to expect form and form_state to be passed into their builder functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant