In Ruby on Rails, is it possible to display a confirmation message if the user has not entered a string in a text field? I have a form whereby a user enters text in a text field and want to show a confirmation message if they do not enter a certain string. A simple example could be a text field where users can enter items they want to buy from the shop, such as "bread, potatoes, eggs", and so a confirmation message would appear when they click submit saying "You have not entered milk, are you sure you want to proceed?".
I am have the below code working when a user clicks "destroy", and so wonder if this can be developed to work when a user clicks "submit"?
<%= link_to 'Destroy', email_path(email), method: :delete, data: { confirm: 'Are you sure?' } %>
data: {confirm: 'Message'}is assigned to the button when the page is loaded. So you could assign a similar message to a Submit button, but it would always appear. It would not work for a conditional that changes based on user input. The slick way to do it would be on the front end with custom Javascript. To do it with Ruby/Rails, you'll need to test the result on the back end and generate a flash message at the controller level.