Ejemplo n.º 1
0
    this.init = function(){
      console.log("Initialize form");

      // Listen for objectedSelected, triggered when items on the map are tapped
      $.subscribe("objectSelected", setSelectedObjectInfo);

      $.subscribe('readyForAddressForm', showObjectFreeForm);

      // Render the form
      api.getForm(renderForm);

      // Add a function to serialize the form for submission to the API
      // usage: form.serializeObject();
      form.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
          if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
              o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
          } else {
            o[this.name] = this.value || '';
          }

          // Don't store blank values for text fields
          if (this.value === '') delete o[this.name];
        });
        return o;
      };
    };
Ejemplo n.º 2
0
  formView.init = function init($el) {
    $form = $el;
    form = $form.find('form');

    // Listen for objectedSelected, triggered when items on the map are tapped
    $.subscribe('selectionReady', setSelectedObjectInfo);

    $.subscribe('readyForAddressForm', showObjectFreeForm);

    // Render the form
    api.getForm(renderForm);

    // Add a function to serialize the form for submission to the API
    // usage: form.serializeObject();
    form.serializeObject = function() {
      var o = {};
      var a = this.serializeArray();
      $.each(a, function() {
        // Don't store blank values for text fields
        if (this.value === '') {
          return;
        }
        if (o[this.name] !== undefined) {
          if (!o[this.name].push) {
            o[this.name] = [o[this.name]];
          }
          o[this.name].push(this.value || '');
        } else {
          o[this.name] = this.value || '';
        }
      });
      return o;
    };

    form.find('#submitbutton').click(handleSubmit);
  };