Javascript sweetalert2具有max属性的输入编号,错误位置?
我有一个sweetalert模式,带有Javascript sweetalert2具有max属性的输入编号,错误位置?,javascript,jquery,sweetalert,sweetalert2,Javascript,Jquery,Sweetalert,Sweetalert2,我有一个sweetalert模式,带有输入:'number'和输入属性:{min:0,max:foo} 问题是,如果输入值大于允许值(例如max:2,inputed:3),我不知道如何放置错误位置 这是我的代码: $(".addItem").on('click',function() { var _this = $(this); Swal.fire({ title :"add "+_this.data('title'), input
输入:'number'
和输入属性:{min:0,max:foo}
问题是,如果输入值大于允许值(例如max:2,inputed:3),我不知道如何放置错误位置
这是我的代码:
$(".addItem").on('click',function()
{
var _this = $(this);
Swal.fire({
title :"add "+_this.data('title'),
input : 'number',
inputAttributes: {
min: 0,
max: _this.data('maximum')
}
});
});
在这种情况下,我在最大值为“1”的字段中输入“2”,然后sweetalert模式按钮上方出现错误。我想知道如何放置错误位置?在preConfirm:function(value){…}
内部使用Swal.showValidationError('bar')
对我不起作用。谢谢你的帮助
没关系,我用
inputValidator: (value) => {
if (value > _this.data('maximum')) {
return 'quantity should not exceed available stock! <small>stock :'+_this.data('maximum')+'</small>'
}
}
inputValidator:(值)=>{
如果(值>\此.data('最大值')){
return“数量不应超过可用库存!库存:”+_this.data('maximum')+“”
}
}
上面的输入属性:{foo:bar}
您可以使用
let{value:cantidad}=wait Swal.fire({
标题:“康蒂达”,
html:“Cantidad máxima:“+Cantidad_existencia+”
“,
输入:“数字”,
输入占位符:“Cantidad”,
输入值:1,
输入属性:{
民:1,,
马克斯:康蒂达德·奥古斯提亚,
步骤:1,
模式:“[0-9]{10}”
},
inputValidator:(值)=>{
如果(值>cantidad_存在){
返回'La cantidad Ingreada supera a La cantidad en inventario'
}
如果(值<0){
返回“La cantidad Ingreada no tiene Senido”
}
如果(值==0){
返回“无特殊情况”
}
},
confirmButtonText:`Establecer`,
})
let { value: cantidad } = await Swal.fire({
title: "Cantidad",
html: "Cantidad máxima: " + cantidad_existencia + "<br> ",
input: "number",
inputPlaceholder: 'Cantidad',
inputValue: 1,
inputAttributes: {
min: 1,
max: cantidad_existencia,
step: 1,
pattern: "[0-9]{10}"
},
inputValidator: (value) => {
if (value > cantidad_existencia) {
return 'La cantidad ingresada supera a la cantidad en inventario'
}
if (value < 0) {
return 'La cantidad ingresada no tiene sentido'
}
if (value == 0) {
return 'No ha especificado cuanto va a comprar'
}
},
confirmButtonText: `Establecer`,
})