How to validate user input with async function?
See original GitHub issueI have to validate a user email with my backend using a fetch call. Can I do this? I’m trying with async/await but does not work.
My code:
function resolveClientEmailAddress(email) {
return new Promise(resolve => {
let data = new FormData();
data.append( "client", email);
fetch(config.server.remote + "api/client-by-mail/", {
method: "POST",
body: data
}).then(function(res){ return res.json(); }).then(function(data){
resolve(data)
}).catch(function (error) {
console.log("CATCH ----> ERROR ===> ", error)
});
});
}
async function clientEmailValidator(email) {
let response = await resolveClientEmailAddress(email);
console.log("clientEmailValidator ===> ", response); // 10
if (response.hasOwnProperty('error_message'))
return response.error_message;
else
return true
}
let chatbotQuestionList = [{
id: '1',
message: 'Welcome',
trigger: '2',
},{
id: '2',
message: "Insert your email address",
trigger: '3',
},{
id: '3',
user: true,
validator: clientEmailValidator,
trigger: 'end',
},{
id: 'end',
message: 'Ok',
end: true,
}];
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
async js validation form - javascript - Stack Overflow
The problem is that to var isInvalid in checkValidity method is returned promise.
Read more >javascript - await user input with async/await syntax
I would love to not have to only use async/await to wait for web resources to come back but also to wait for...
Read more >Async Change Validation Example - Redux Form
To provide asynchronous validation, provide redux-form with an asynchronous validation function ( asyncValidate ) that takes an object of form values, ...
Read more >Synchronous and asynchronous input validation with ag-Grid
This function will be used to validate the value entered by the user. The syncValidator is responsible for input validation and calling the...
Read more >Async Validators | JET Developer Cookbook - Oracle
The async validator's validate method returns a Promise that resolves if validation passes and value is updated or rejects with an Error if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes that’s pretty much what I want ! With theses two props and this render for my component:
The behaviour is:
It is just a little bit weird that the bubble disappears and then reappears with the dots… can we set the botDelay to 0 for a single step ?
Edit: found it: the
delayoption on the step, sorry !The render is amazing ! Thank you !
Please try to add the
asMessage: trueandreplace: trueprops in the custom step. Not sure if will work as you want.