Formatting Error Message in rails - ruby-on-rails

I have a stock validation error message that displays on the top of the screen when a field isn't met. I would like to format the message so that they display next to the field, instead of on the top of the screen. Does anyone know how I could do that?

There is a gem out there called client_side_validation which does exactly what you are looking to do. Also check out the RailsCast for an example on how to get set up with the validation library.

Related

Check in view that form have errors?

(ZF2) Is there a possibility to check in view that the form is displayed for the first time, or "returned" because of errors?
Of course I can in controller base on isValid add additional variable, but I'm curious if there is a ready solution to this?
You can check if the form has been validated with $form->hasValidated() if it hasn't you prob can be pretty sure it's displayed for "the first time".
Additionally you could check if the form contains any error messages $form->getMessages(). That way you could tell if it is validated and contains validation errors.

How to add multiple message validation in only one growl message

I have a p:growl for show message validation, but it shows a growl for each message validation, is there any way to show multiples messages validation in only one message p:growl?
It's just how the growl works. Each message will appear in its own panel. I don't think you can change it unless you develop a custom growl component on your own and put <p:messages> in it :)
As Mr.J4mes has mentioned, it's not a 'add on' function of Growl, you could however get PrimeFaces source and recompile it with your changes/requirements.
GrowlRenderer, puts all of the messages into a JSON object e.g..
{summary:"Successful",detail:"Hello ss",severity:'info'},{summary:"Second Message",detail:"Additional Info Here...",severity:'info'}]});});
Then the grow.js line 32 does a for each loop of 'each mesage', and does a render... using renderMessage on line 50. (may may not change depends fversion you're using)...
basically, you could do several things to fix it, (ie pass in all objects not for each and do it in the renderMessage, or keep as is but just don't end the tags until all messages are finished)..
This is less work than creating your own widget etc, adding a var to the primefaces widget, and conditionally doing this is probably a better option - otherwise you're totlally overwriting the functionality.

Adding one error message to two checkboxes in Rails

I have two checkboxes that I'm adding a simple custom validator on. I want to check that either one or the other (or both) are checked, but that they aren't both empty.
To do this, I've written put a simple unless checkbox1 || checkbox2 line in my custom validator method. However, when outputting the error message, I realized that the error.add takes the form field as first parameter. I don't want the error message to be specifically for one of the other checkbox; I just want it to say, one or both need to be selected.
How can I do this?
Just found the answer:
errors.add(:base, 'Generic error message')

Oracle Forms - Display message blocks rest of the code execution or message doesn't show

I'm trying to show a message on a form without success.
What I'm doing is: When a new line is clicked, I use the WHEN-NEW-RECORD-INSTANCE to do some verifications and some enabling/disabling on the form and showing up the message. The problem is sometimes it does the enabling/disabling but not the message, then I click another line and it shows the previous message but doesn't do the enabling/disabling...
I've already tried some stuff like:
message('message');
n := Show_alert('message');
with and without SYNCHRONIZE;
I don't think it's the code itself blocking the messages... or I'm missing something...
Does anyone ever had this problem?
Can someone tell me the various options to display messages and their differences?
Thanks.
I managed to fix this using the WHEN-MOUSE-CLICK trigger instead.
I didn't want to use this at first because when I clicked the already selected line it would show the message again but I made some code verification and fixed it.
Someone can close this.
thanks.

Omit attribute name from validation error message (at start of it)?

I write code in English but I'm currently doing a site which is fully translated to another language (validation error messages included). However, I have a problem because validation error messages always seem to include the name of the attribute the error is on at the start of the error, e.g.:
Title Prosimo izpolnite naziv fakultete.
I want to get rid of the Title at the start, like so:
Prosimo izpolnite naziv fakultete.
Any help is appreciated. I would rather see if this can be solved without installing any 3rd party plugins.
If it's possible to provide translations for attribute names, that would be a cool solution too, but I would still like to know how it can be done both ways (omit or translate).
There is no need to use the error_messages_for helper for errors, you can write your own helper using the record's errors attribute.
You can just iterate over the error objects and display their messages.

Resources