Authored by weiqingting

验证修改

... ... @@ -18,7 +18,7 @@ $("button").click(function(){
})*/
var $=require('jquery');
var Validator = require('../util/validate');
var Validator = require('./validate');
require('./upload');
require('../util/datepicker');
require('../util/jquery.gritter');
... ... @@ -200,6 +200,8 @@ edit.prototype={
var that=this;
var rules = {},data = {},attributes={};
var err=[];
$("input:text",that.el)
.add("input[type=number]",that.el)
.add("input[type=file]",that.el)
... ... @@ -212,14 +214,16 @@ edit.prototype={
value=!!$(this).attr("value")?$(this).attr("value"):$(this).val();
}
var name=$(this).attr("placeholder")&&!(/^\d+$/.test($(this).attr("placeholder")))?$(this).attr("placeholder").replace(/请填写/g,''):$(this).parents(".form-group").find("label").text().replace(/\*/g,'');
var rule = [];
// var rule = [];
if ($(this).attr("required")) {
rule.push("required");
rules[id] = rule.join('|');
data[id] = value;
attributes[id]=name;
new Validator.init(document.getElementById(id),{
rules:{required:true}
}).validate(function(obj){
err.push("<p>"+name+"不可为空</p>");
});
}
// if ($(this).attr("maxlength")) {
// rule.push("max:" + $(this).attr("maxlength"));
// }
... ... @@ -238,13 +242,17 @@ edit.prototype={
});
var v = Validator.make(data, rules);
v.mergeAttribute(attributes);
var err=[];
if (v.fails()) {
for(var key in v.messages()){
err.push("<p>"+v.messages()[key]+"</p>");
}
// var v = Validator.make(data, rules);
// v.mergeAttribute(attributes);
// var err=[];
// if (v.fails()) {
// for(var key in v.messages()){
// err.push("<p>"+v.messages()[key]+"</p>");
// }
// that.__err(err.join(''));
// return false;
// }
if(err.length>0){
that.__err(err.join(''));
return false;
}
... ... @@ -299,7 +307,7 @@ edit.prototype={
}
};
callback&&callback(options);
$.ajax(options);
//$.ajax(options);
return false;
},
__listen:function(key,o,callback){
... ... @@ -335,7 +343,8 @@ edit.ajaxfileupload=function(el,option){
'action': '/ajax/upload',
'params':$.extend({},{__type:"fileupload-upload"},option.params),
onComplete:option.onComplete,
onStart: option.onStart
onStart: option.onStart,
valid_extensions:["xlsx"]
})
}
edit.prototype.init.prototype=edit.prototype;
... ...
... ... @@ -10,7 +10,7 @@ $.fn.ajaxfileupload = function(options) {
onComplete: function(response) { },
onCancel: function() { },
validate_extensions : true,
valid_extensions : ['gif','png','jpg','jpeg','xlsx'],
valid_extensions : ['gif','png','jpg','jpeg'],
submit_button : null
};
... ... @@ -54,7 +54,7 @@ $.fn.ajaxfileupload = function(options) {
var ext = $element.val().split('.').pop().toLowerCase();
if(true === settings.validate_extensions && $.inArray(ext, settings.valid_extensions) == -1)
{
settings.onComplete.apply($element, [{status: false, message: 'The select file type is invalid. File must be ' + settings.valid_extensions.join(', ') + '.'}, settings.params]);
settings.onComplete.apply($element, [{status: false, message: '文件类型无效.只支持'+settings.valid_extensions.join(',')}, settings.params]);
} else
{
uploading_file = true;
... ... @@ -78,7 +78,13 @@ $.fn.ajaxfileupload = function(options) {
element.unwrap();
uploading_file = false;
settings.onComplete.apply(element, [response, settings.params]);
var _$element=$element.clone();
var _$parent=$element.parent();
$element.remove();
_$parent.append(_$element);
_$element.ajaxfileupload(settings);
};
var wrapElement = function(element) {
var frame_id = 'ajaxUploader-iframe-' + Math.round(new Date().getTime() / 1000)
... ...
... ... @@ -42,14 +42,14 @@ var Validate = function(element, options) {
var defaults = {
regExps: regExps,
messages: messages
messages: "messages"
};
this.options = _extend({}, defaults, options);
this.element = element;
this.regExps = regExps;
};
var fn = Validate.prototype;
fn.validate = function() {
fn.validate = function(onError) {
var isValid = true;
this.value = this.element.value;
for (var rule in this.options.rules) {
... ... @@ -62,7 +62,7 @@ fn.validate = function() {
if (!this[rule](param)) {
isValid = false;
this.message = "Error"//_createMessage(this.options.messages[rule], {rule: param, data: this.value});
this.options.onError.call(this);
onError&&onError.call(null,this);
break;
}
}
... ...
... ... @@ -34,7 +34,7 @@ $('.leftpanel .nav .parent>a').click(function() {
$(".leftpanel .nav .children a").each(function(){
var attr=$(this).attr("href");
if(attr==window.location.pathname){
if(attr==window.location.pathname+window.location.search){
$(this).parents(".children").show();
$(this).parent("li").addClass("active");
$(this).parents(".parent").addClass("parent-focus");
... ...
... ... @@ -20,14 +20,18 @@ var edit=require('../common/edit');
if($("#promotionInfo").val()){
var __promotionInfo = JSON.parse($("#promotionInfo").val());
$("#promotionInfo-type").val(__promotionInfo["type"]);
$("input:radio[name=promotionInfo-type]").each(function(){
if($(this).val()==__promotionInfo["type"]){
$(this).prop("checked","checked");
if($(this).val()=="3"){
$("#resultdiscount").hide();
}
}
});
$("#promotionInfo-condition-amount_at_least").val(__promotionInfo["condition"]["amount_at_least"]);
$("#promotionInfo-condition-count_at_least").val(__promotionInfo["condition"]["count_at_least"]);
$("#promotionInfo-action-discount").val(__promotionInfo["action"]["discount"]);
$("#promotionInfo-action-discount_at_most").val(__promotionInfo["action"]["discount_at_most"]);
if ($("#promotionInfo-type").val() == "3") {
$("#resultdiscount").hide();
}
}
});
... ... @@ -74,12 +78,10 @@ var edit=require('../common/edit');
$discount = $("#promotionInfo-action-discount");
$("input:radio[name=promotionInfo-type]").change(function(){
var $checked=$(this);
if ($checked.prop("name") == "promotionInfo-type") {
if ($checked.val() == "3") {
$discount.prop("disabled", true).val("0.00").parents("#resultdiscount").hide();
} else {
$discount.prop("disabled", false).parents("#resultdiscount").show();
}
if ($checked.val() == "3") {
$discount.prop("disabled", true).val("0.00").parent("#resultdiscount").hide();
} else {
$discount.prop("disabled", false).parent("#resultdiscount").show();
}
});
});
... ...
... ... @@ -100,7 +100,7 @@
<input type="radio" value="3" name="promotionInfo-type"> 满减
</label>
</div>
<!-- <input type="hidden" value="1" id="promotionInfo-type"> -->
<!-- <input type="hidden" value="1" id="promotionInfo-type"> -->
<!-- required checked-->
</div>
... ...