Jason K
Jason K

Reputation: 1381

w2ui ignoring value in html form

w2ui is ignoring the value on the input tag.

How do I get it to use the value?

It reads the selects just fine.

w2ui form

jsfiddle.net

<div id="form" style="width: 750px;">
<div class="w2ui-page page-0">
  <div class="w2ui-field">
    <label>First Name:</label>
    <div>
      <input name="first_name" type="text" value="John" />
    </div>
  </div>
</div>
<div class="w2ui-buttons">
  <button class="w2ui-btn" name="reset">Reset</button>
  <button class="w2ui-btn" name="save">Save</button>
</div>
</div>

$(function() {
$('#form').w2form({
  name: 'form',
  url: 'server/post',
  fields: [
    { field: 'first_name', type: 'text', required: true }
  ],
  actions: {
    reset: function() {
      this.clear();
    },
    save: function() {
      this.save();
    }
  }
});
});

If I have to write JavaScript. How would I access the fields?

Upvotes: 2

Views: 394

Answers (2)

Code.king
Code.king

Reputation: 47

additionally, As documentation of w2ui , you can set the value of input field

w2ui.Your_Form_Name.record['You_InputField_Name'] = The_New_value;

and then call form refresh to update both html and object, but this has issue where it clear the previous drop list select , so do set the new value with code as the following to avoid use refresh and keep pre-select in drop list

$('#InputFiled_Name').val(The_New_Value); w2ui.Your_Form_name.record['Your_InputField_Name'] = The_New_Value;

Upvotes: 0

Mike Scotty
Mike Scotty

Reputation: 10782

You can access the value of the input with form.record.

In your case w2ui.form.record.first_name (where form is the name of your w2form).

In your save event you can access the record with this.record, e.g.:

    save: function() {
        console.log(this.record);
        console.log(this.record.first_name);
        this.save();
    }

Upvotes: 1

Related Questions