简体   繁体   English

余烬等待用户填写表格

[英]ember waiting for user to complete the form

In ember, I have a form which ask the user their username and password for our remote server and then I want to verify the credentials by making an ajax call. 在ember中,我有一个表单,该表单询问用户其远程服务器的用户名和密码,然后我想通过进行ajax调用来验证凭据。 Currently, I am using a custom made component which allows me to bind any action on clicking next or submit where I can verify the credentials and throw errors if needed. 当前,我使用的是定制组件,该组件使我可以在单击“下一步”时绑定任何操作,或者在可以提交凭据的地方进行提交,并在需要时抛出错误。 But once an error will occur, user cant click the next button (the way component is implemented) and hence second time validation is not happening. 但是一旦发生错误,用户将无法单击下一步按钮(组件的实现方式),因此不会进行第二次验证。 So, I thought to make a computed property which will look for username and password (and hence make ajax call when entered). 因此,我认为要创建一个计算属性,该属性将查找用户名和密码(因此在输入时进行ajax调用)。 But the problem with this approach is: every time something is entered in these boxes, computed property gets triggered which makes an ajax call (i dont want to make so many network calls for no purpose). 但是这种方法的问题是:每次在这些框中输入内容时,都会触发计算属性,该属性将进行ajax调用(我不想无故进行多次网络调用)。 Is there a way in ember where we can wait for user to finish the input and then invoke any kind of action? 在ember中,有什么方法可以等待用户完成输入然后调用任何类型的操作?

Better approach is to use oninput with action: 更好的方法是将oninput与action结合使用:

<input oninput={{action "onInput" value="target.value"}}> 

and then from action onInput debounce call to ajax function using debounceTask from ember-lifeline addon(this example), or using ember-concurrency: 然后从ember-lifeline插件中的debounceTask (此示例),或使用ember-concurrency,从onInput动作对ajax函数的去抖动调用:

actions: {
   onInput(val){
      debounceTask(this, 'sendAjax', val, 500);
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM