Skip to content

Commit 9082ced

Browse files
pre-populate form
1 parent 8124198 commit 9082ced

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/mm-form/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,22 @@
9494
'input' : {
9595
validation: 'int|empty',
9696
errorMsg: 'You need to type a number',
97-
label: 'Type a number'
97+
label: 'Type a number',
98+
// value: '100'
9899
},
99100
'dropdown' : {
100101
validation: 'empty',
101102
errorMsg: 'You need to select an item',
102-
label: 'Select an Item'
103+
label: 'Select an Item',
104+
// value: 'List Item 4'
103105
},
104106
'radio' : {
105107
validation: function(name, value, data) {
106108
return data[name] === 'Red' && value === 'Red';
107109
},
108110
errorMsg: 'You need to select \'Red\'',
109-
label: 'Select a Color'
111+
label: 'Select a Color',
112+
// value: 'Red'
110113
}
111114
},
112115
// returned from server-side validation(?)

src/mm-form/mm-form.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,24 @@
120120
value = this.data[key].value || null;
121121

122122
// If there was an initial value set in markup, use that
123-
// However, values set in the config will always 'win':
123+
// However, values set in the config will always 'win'
124124
if (field.value && value === null) {
125125
value = field.value;
126126
}
127127

128-
// store the field and parent element just in case we need
129-
// to reference those later
128+
// Store the field and parent element just in case
129+
// we need to reference those later
130130
this.data[name].field = field;
131131
this.data[name].parentEle = parentEle;
132132

133133
this._updateData(name, value);
134134
this._createErrorMsg(name, parentEle, errorMsg);
135135
this._createLabel(name, parentEle, field, label);
136+
137+
// Populate the fields if necessary
138+
if (!field.value && value) {
139+
field.value = value;
140+
}
136141
}
137142
},
138143

0 commit comments

Comments
 (0)