jQuery即兴回调问题-$ .prompt失败 [英] Jquery Impromptu Callback issue - $.prompt fails
问题描述
我遇到 jQuery即兴的问题,特别是$ .prompt,它具有用于内联表单的回调函数.
I have an issue with jQuery Impromptu, specifically $.prompt with a callback function for an inline form.
现在,实际的具体问题如下.如果email_address
字段在提交时为空白,则无法使$.prompt('Please supply an email address for the customer')
正常工作,但是如果将其更改为alert('Please supply an email address for the customer')
则可以正常工作.
Now, the actual specific problem is the following. If the email_address
field is blank when submitted I cannot get the $.prompt('Please supply an email address for the customer')
to work, however if I change it to alert('Please supply an email address for the customer')
it will work.
我猜这是一个范围问题,因为其他$.prompt
调用按预期运行,我认为这是因为它们在$.post
回调函数中.
I am guessing this is a scope issue as the other $.prompt
calls work as expected which I assume are because they are inside a $.post
callback function.
我一直在努力寻找大量有关回调表单功能的文档,尽管我觉得我理解e
,v
和f
变量,但m
(消息)却不是我想要的以前用过.当我将m
登录到控制台日志时,它看起来像jQuery Impromptu对象,但是我不确定如何访问它的属性.我已经尝试过m.prompt()
和$.m.prompt()
,但是这些只是我如何访问prompt
函数的猜测.
I have struggled to find a huge amount of documentation of the callback form functionality and although I feel like I understand the e
, v
and f
variables, the m
(Message) is not something I've used before. When I log m
to the console log it looks like the jQuery Impromptu object, however I am unsure how to access a property of it. I have tried m.prompt()
and $.m.prompt()
but these are just guesses on how I would access the prompt
function.
JavaScript
var txt = '<input type="text" name="email_address" value="" />';
function mycallbackform(e,v,m,f)
{
if(v != undefined)
{
if (v == true)
{
console.log(f);
if (f.email_address.length == 0)
{
console.log(m);
$.prompt('Please supply an email address for the customer');
}
else
{
$.post('". $this->view->url(array(), 'admin-create-user-from-checkout') ."', f, function(data) {
if(data.status)
{
$.prompt('Customer Record Created Successfully');
}
else
{
$.prompt('Customer Record could not be created');
$('#email_address').val($('#old_email_address').val());
}
}, 'json');
}
}
else
{
$('#email_address').val($('#old_email_address').val());
}
}
$.prompt(txt,{callback: mycallbackform, buttons: { Ok: true, Cancel: false }});
m
的控制台日志
Console Log for m
Object[div.jqimessage]
0
div.jqimessage
context
undefined
jquery
"1.7.2"
length
1
prevObject
Object[div#jqi_state_state0.jqi_state]
selector
".children(#jqi) #jqi_st...0.children(.jqimessage)"
constructor
function()
init
function()
_toggle
function()
add
function()
addClass
function()
affix
function()
after
function()
ajaxComplete
function()
ajaxError
function()
ajaxSend
function()
ajaxStart
function()
ajaxStop
function()
ajaxSuccess
function()
alert
function()
andSelf
function()
animate
function()
append
function()
appendTo
function()
attr
function()
before
function()
bind
function()
blur
function()
button
function()
carousel
function()
change
function()
children
function()
clearQueue
function()
click
function()
clone
function()
closest
function()
collapse
function()
contents
function()
contextmenu
function()
css
function()
data
function()
dblclick
function()
delay
function()
delegate
function()
dequeue
function()
detach
function()
die
function()
domManip
function()
dropdown
function()
each
function()
empty
function()
end
function()
eq
function()
error
function()
extend
function()
fadeIn
function()
fadeOut
function()
fadeTo
function()
fadeToggle
function()
filter
function()
find
function()
first
function()
focus
function()
focusin
function()
focusout
function()
get
function()
has
function()
hasClass
function()
height
function()
hide
function()
hover
function()
html
function()
index
function()
innerHeight
function()
innerWidth
function()
insertAfter
function()
insertBefore
function()
is
function()
keydown
function()
keypress
function()
keyup
function()
last
function()
live
function()
load
function()
map
function()
modal
function()
mousedown
function()
mouseenter
function()
mouseleave
function()
mousemove
function()
mouseout
function()
mouseover
function()
mouseup
function()
next
function()
nextAll
function()
nextUntil
function()
not
function()
off
function()
offset
function()
offsetParent
function()
on
function()
one
function()
outerHeight
function()
outerWidth
function()
parent
function()
parents
function()
parentsUntil
function()
popover
function()
position
function()
prepend
function()
prependTo
function()
prev
function()
prevAll
function()
prevUntil
function()
promise
function()
prompt
function()
promptDropIn
function()
prop
function()
push
push()
pushStack
function()
queue
function()
ready
function()
remove
function()
removeAttr
function()
removeClass
function()
removeData
function()
removeProp
function()
replaceAll
function()
replaceWith
function()
resize
function()
revmaxslide
function()
revnext
function()
revolution
function()
revpause
function()
revprev
function()
revresume
function()
revshowslide
function()
scroll
function()
scrollLeft
function()
scrollTop
function()
scrollspy
function()
select
function()
serialize
function()
serializeArray
function()
show
function()
siblings
function()
size
function()
slice
function()
slideDown
function()
slideToggle
function()
slideUp
function()
sort
sort()
splice
splice()
stop
function()
submit
function()
swipe
function()
tab
function()
text
function()
toArray
function()
toggle
function()
toggleClass
function()
tooltip
function()
transit
function()
transition
function()
trigger
function()
triggerHandler
function()
typeahead
function()
unbind
function()
undelegate
function()
unload
function()
unwrap
function()
val
function()
waitForImages
function()
width
function()
wrap
function()
wrapAll
function()
wrapInner
function()
__proto__
Object[]
推荐答案
问题已解决!
@link: https://github.com/trentrichardson/jQuery-Impromptu/issues/6
报价
使用新的事件系统,回调将绑定到提示上.因此,必须在销毁提示之前调用回调. Impromptu不能一次用于多个提示.
With the new event system the callback is bound onto the prompt. So callback must be called before the prompt is destroyed. Impromptu is not intended for multiple prompts at one time.
如果您要解决此问题,一个简单的解决方案是setTimeout(10,function(){$ .prompt(...);});在回调内部.这将为上一个提示关闭提供机会.
If you should want to work around this an easy solution would be to setTimeout(10, function(){ $.prompt(...); }); Inside of the callback. This will give opportunity for the previous prompt to close.
固定的Javascript
var txt = '<input type="text" name="email_address" value="" />';
function mycallbackform(e,v,m,f)
{
if(v != undefined)
{
if (v == true)
{
if (f.email_address.length == 0)
{
setTimeout(function(){ $.prompt('Please supply an email address for the customer'); }, 10);
}
else
{
$.post('". $this->view->url(array(), 'admin-create-user-from-checkout') ."', f, function(data) {
if(data.status)
{
$.prompt('Customer Record Created Successfully');
}
else
{
$.prompt('Customer Record could not be created');
$('#email_address').val($('#old_email_address').val());
}
}, 'json');
}
}
else
{
$('#email_address').val($('#old_email_address').val());
}
}
$.prompt(txt,{callback: mycallbackform, buttons: { Ok: true, Cancel: false }});
这篇关于jQuery即兴回调问题-$ .prompt失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!