2

I am trying to build a Rails application with w2ui.

I have hit my first snag when trying to submit a form built with w2ui.

I have a simple model called Project with two attributes: name and description.

The standard, scaffolded form built by Rails submits the form data as follows:

project[name]:Test Project
project[description]:A description

However, the form data submitted by w2ui looks as follows:

record[project[name]]:Test Project
record[project[description]]:A description

That is, w2ui wraps the data further in a record variable, which means I must either change the controller in Rails, which I am not wanting to do, or find a way to get w2ui to not wrap the data the way it does.

My code for w2ui is taken pretty much straight from their demos:

$(function () {
    $('#project_form').w2form({
        name  : 'project_form',
        url   : '/projects.json',
        fields: [
            { name: 'project[name]', type: 'text', required: true },
            { name: 'project[description]',  type: 'text' }
        ],
        actions: {
            reset: function () {
                this.clear();
            },
            save: function () {
                this.submit(); // tried .save() as well, same result
            }
        }
    });
});

First prize would be if w2ui could be configured to do this. Any ideas? I don't see anything in the w2ui docs...

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95

1 Answers1

1

I faced the same problem and straight away could not get a solution. I added the below to form options, it just copies all params inside record to post data.

  onSubmit: function(formName, formObj){
    $.extend(formObj.postData, formObj.postData.record);
  },

Its been long you have asked this question, if you knew a better solution please let me know.

Muthukannan Kanniappan
  • 2,080
  • 1
  • 16
  • 18