forked from 0x2620/oxjs
updating form elements
This commit is contained in:
parent
8550cc8442
commit
73f1105692
13 changed files with 305 additions and 140 deletions
|
|
@ -45,19 +45,9 @@ Ox.FormPanel = function(options, self) {
|
|||
width: 240
|
||||
}
|
||||
],
|
||||
items: function(data, callback) {
|
||||
setTimeout(function() {
|
||||
callback({
|
||||
data: {
|
||||
items: Ox.isEmpty(data)
|
||||
? self.sections.length
|
||||
: self.options.form.map(function(section) {
|
||||
return {title: section.title, valid: section.valid};
|
||||
})
|
||||
}
|
||||
});
|
||||
}, 250);
|
||||
},
|
||||
items: self.options.form.map(function(section) {
|
||||
return {title: section.title, valid: false};
|
||||
}),
|
||||
max: 1,
|
||||
min: 1,
|
||||
selected: [self.sections[0].id],
|
||||
|
|
@ -90,7 +80,7 @@ Ox.FormPanel = function(options, self) {
|
|||
.append(
|
||||
$('<div>')
|
||||
.css({marginBottom: '8px', fontWeight: 'bold'})
|
||||
.html(section.title)
|
||||
.html((i + 1) + '. ' + section.title)
|
||||
)
|
||||
.append(
|
||||
$('<div>')
|
||||
|
|
@ -99,27 +89,22 @@ Ox.FormPanel = function(options, self) {
|
|||
)
|
||||
.append(
|
||||
self.$forms[i] = Ox.Form({
|
||||
items: section.items
|
||||
items: section.items,
|
||||
validate: section.validate
|
||||
})
|
||||
.bindEvent({
|
||||
change: function(data) {
|
||||
var valid;
|
||||
if (section.validate) {
|
||||
valid = section.validate(section.title, data);
|
||||
self.$list.value(section.title, 'valid', valid);
|
||||
that.triggerEvent('validate', {
|
||||
title: section.title,
|
||||
data: {valid: valid}
|
||||
});
|
||||
}
|
||||
//var valid = section.validate(section.title, data);
|
||||
//self.$list.value(section.title, 'valid', valid);
|
||||
//that.triggerEvent('change', data);
|
||||
Ox.Log('FORM', '---CHANGE---', data, self.$forms[i].valid())
|
||||
self.$list.value(section.title, 'valid', self.$forms[i].valid());
|
||||
that.triggerEvent('change', {
|
||||
section: section.title,
|
||||
data: data
|
||||
});
|
||||
},
|
||||
validate: function(data) {
|
||||
self.$list.value(section.title, 'valid', data.valid);
|
||||
that.triggerEvent('validate', {
|
||||
title: section.title,
|
||||
section: section.title,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
|
@ -129,6 +114,11 @@ Ox.FormPanel = function(options, self) {
|
|||
.appendTo(self.$section);
|
||||
});
|
||||
|
||||
self.$forms.forEach(function($form, i) {
|
||||
Ox.print(self.sections[i], 'valid', $form.valid());
|
||||
self.$list.value(self.sections[i], 'valid', $form.valid());
|
||||
});
|
||||
|
||||
self.$sections[0].show();
|
||||
|
||||
that.$element = Ox.SplitPanel({
|
||||
|
|
@ -157,6 +147,44 @@ Ox.FormPanel = function(options, self) {
|
|||
return index;
|
||||
}
|
||||
|
||||
that.renderPrintVersion = function(title) {
|
||||
var $printVersion = $('<div>').css({overflowY: 'auto'});
|
||||
$printVersion.append(
|
||||
$('<div>')
|
||||
.addClass('OxFormSectionTitle')
|
||||
.css({
|
||||
height: '16px',
|
||||
padding: '16px 16px 8px 16px',
|
||||
fontWeight: 'bold'
|
||||
})
|
||||
.html(title)
|
||||
);
|
||||
self.$sections.forEach(function($section, i) {
|
||||
// jQuery bug: textarea html/val does not survive cloning
|
||||
// http://bugs.jquery.com/ticket/3016
|
||||
var $clone = $section.clone(true),
|
||||
textareas = {
|
||||
section: $section.find('textarea'),
|
||||
clone: $clone.find('textarea')
|
||||
};
|
||||
textareas.section.each(function(i) {
|
||||
$(textareas.clone[i]).val($(this).val());
|
||||
});
|
||||
$printVersion
|
||||
.append(
|
||||
$('<div>').css({
|
||||
height: '1px',
|
||||
margin: '8px 0 8px 0',
|
||||
background: 'rgb(128, 128, 128)'
|
||||
})
|
||||
)
|
||||
.append(
|
||||
$clone.show()
|
||||
);
|
||||
});
|
||||
return $printVersion;
|
||||
};
|
||||
|
||||
that.values = function() {
|
||||
var values = {};
|
||||
self.options.form.forEach(function(section, i) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue