add required in editorFactory

add required in editorFactory
This commit is contained in:
daisyonly 2014-08-26 17:37:54 +08:00
parent edb85afd67
commit 6eba56d7f8
1 changed files with 23 additions and 11 deletions

View File

@ -50,14 +50,14 @@ EditorFactory.prototype.createChoice = function(value, defaultValue, name,
return div;
}
EditorFactory.prototype.createField = function(label, name, size, id, value) {
EditorFactory.prototype.createField = function(label, name, required, size, id, value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "field");
$(div).children(".editor").append(this.createFieldLine(size, name, value));
$(div).children(".editor").append(this.createFieldLine(size, name, required, value));
return div;
}
EditorFactory.prototype.createMultiField = function(label, name, size, id,
EditorFactory.prototype.createMultiField = function(label, name, required, size, id,
value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "multiField");
@ -65,7 +65,7 @@ EditorFactory.prototype.createMultiField = function(label, name, size, id,
var values = value.split(";");
for (var i = 0; i < values.length; i++) {
$(div).children(".editor").append(
this.createFieldLine(size, name, values[i]));
this.createFieldLine(size, name, required, values[i]));
}
}
@ -94,19 +94,22 @@ EditorFactory.prototype.createMultiField = function(label, name, size, id,
return div;
}
EditorFactory.prototype.createFieldLine = function(size, name, value) {
EditorFactory.prototype.createFieldLine = function(size, name, required, value) {
var fieldDiv = document.createElement("div");
$(fieldDiv).addClass("field");
var fieldName = document.createElement("label");
$(fieldName).html(name);
var field = document.createElement("input");
$(field).attr("type", "text");
if(required=="true"){
$(field).attr("required", "required");
}
// $(field).attr("maxlength", size);
$(field).attr("value", value);
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
EditorFactory.prototype.createFile = function(label, name, size, id, value) {
EditorFactory.prototype.createFile = function(label, name, required, size, id, value) {
if (size == null || size <= 0) {
size = 150;
}
@ -119,6 +122,9 @@ EditorFactory.prototype.createFile = function(label, name, size, id, value) {
$(fieldName).html(name);
var file = document.createElement("input");
$(file).attr("type", "file");
if(required == "true"){
$(field).attr("required", "required");
}
// $(field).attr("maxlength", size);
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).children(".editor").append(fileEditor);
@ -134,7 +140,7 @@ EditorFactory.prototype.createTable = /**
* @param value
* @returns
*/
function(label, name, cols, id, value) {
function(label, name, required, cols, id, value) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").attr("editorType", "table");
@ -152,7 +158,7 @@ function(label, name, cols, id, value) {
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").append(
createTr(event.data.headers, event.data.fieldName));
createTr(event.data.headers, event.data.fieldName, required));
});
var deleteButton = document.createElement("button");
$(deleteButton).html("remove");
@ -188,7 +194,7 @@ function(label, name, cols, id, value) {
var tbody = document.createElement("tbody");
$(thead).append(createHeader(headers));
for (var i = 0; i < values.length; i++) {//this minus one because there is a "|;" in the end of value string
$(tbody).append(createTr(headers, name, values[i]));
$(tbody).append(createTr(headers, name, required, values[i]));
}
$(table).append(thead);
@ -208,7 +214,7 @@ function(label, name, cols, id, value) {
}
return tr;
}
function createTr(headers, name, value) {
function createTr(headers, name, required, value) {
value == null? value="":value;
var values = value.split("|");
var tr = document.createElement("tr");
@ -220,6 +226,9 @@ function(label, name, cols, id, value) {
var input = document.createElement("input");
$(input).attr("type", "text");
$(input).attr("style","width:"+"90%");
if(required == "true"){
$(field).attr("required", "required");
}
if(values[i] != undefined){
$(input).val(values[i].split("=")[1]);
}
@ -259,7 +268,7 @@ EditorFactory.prototype.createSelect = function(label, name, size, options, id,
$(div).children(".editor").append(select);
return div;
}
EditorFactory.prototype.createDate = function(label, name, size, id, value) {
EditorFactory.prototype.createDate = function(label, name, required, size, id, value) {
if (size == null || size < 0) {
size = 150
@ -270,6 +279,9 @@ EditorFactory.prototype.createDate = function(label, name, size, id, value) {
$(dateLabel).html(name);
var date = document.createElement("input");
$(date).attr("type", "date");
if(required == "true"){
$(field).attr("required", "required");
}
$(div).children(".editor").append(dateLabel);
$(div).children(".editor").append(date);
return div;