FredrikOseberg / react-chatbot-kit

MIT License
330 stars 159 forks source link

How will prevent empty message or spaces click #196

Open arunachalamv-cyberinnov opened 3 months ago

arunachalamv-cyberinnov commented 3 months ago

image

devo-id commented 2 months ago

I figured out that the Chatbot component provides a validator function. Chatbot properties That function allows you to specify what needs to be considered as a message.

So for your case, it will be like-

const validateInput = (input) =>{
 return input.length > 0 && input.trim().length !=0;
}

<Chatbot
 //other configurations 
  validator={validateInput}
/> 

It will prevent the message from being sent.

rajateshk commented 2 months ago

Worked

I figured out that the Chatbot component provides a validator function. Chatbot properties That function allows you to specify what needs to be considered as a message.

So for your case, it will be like-

const validateInput = (input) =>{
 return input.length > 0 && input.trim().length !=0;
}

<Chatbot
 //other configurations 
  validator={validateInput}
/> 

It will prevent the message from being sent.

Thanks @devo-id to pointing that out.