function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TehNrdTehNrd 

j_id0:j_id10:euCountry1: Value is required --- Help me clean this up.

When you use apex:selectList or apex:inputText you get this nasty error message. Something like this:

 

 

I could live with this for internal apps but I am now working on a force.com site that will face customers and partners so this won't fly.

 

Is there anyway to clean this up? I have many other apex:inputFields with required set to true so I can't do inspection on the apex side to see if the field is null and then display a nice clean message as the requiredness of the other fields prevents the apex from executing.

 

Any ideas? Workarounds?

 

Thanks,

Jason

 

Force2b_MikeForce2b_Mike

Jason,

 

VisualForce errors can be rather cryptic when using the Required="true" tag. You can replace the "j_id0:j_id10:" values with ID's by adding an ID tag to the Page and Form tags. It's still not necessarily a pretty message though.

 

I think in the past I gave on up using Required="true" and did validation in Apex using page Messages or through JavaScript.

 

 

Best Regards,

 

Mike

TehNrdTehNrd

Then it looks like this, not much prettier....

 

 

Page has 25 inputs so I was hoping not to do this with apex or javascript.

rtuttlertuttle

Jason,

 

I have an answer that even I don't like.  You can use the apex:message object, attach it with for="yourid" and assign a special class to it.  Then use an onsubmit or oncomplete to call some jquery or something to fix this crappy message.  That is the best I could think of.  It doesn't accept the title of the field, the alt of the field, or the title of the apex:message object.  Crazy.

 

 

-Richard 

TehNrdTehNrd

Richard,

 

Yup, this is what I was looking at doing right now. It would go something like this.

 

//Style

.customError{
color:#C30000;
}

 

 

<apex:message styleClass="customError" for="euCountry1"/>

//Renders this:
<span class="customError">page:form:euCountry1: Validation Error: Value is required.</span>

 

//Button, must include rerender for this to work properly.

<apex:commandButton value="Submit Registration" action="{!save}" status="submit" rerender="form" oncomplete="cleanErrors();" />

 

//$jQueryness

<apex:includeScript value="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"/>
<script type="text/javascript">
function cleanErrors(){
$('.customError').each(function(index) {
$(this).html('<strong>Error:</strong> You must enter a value');
});
}
</script>

 

This is not ideal but it gets the job done. It is better than verifying every field for null in apex. Thanks for the help.

 

-Jason

Message Edited by TehNrd on 01-26-2010 03:43 PM
AcronymAcronym
How do I reproduce this behavior?
BeeddiskShahBeeddiskShah

Why is it that we need to write a separate JS for the function? Can't you just make the field free flowing and no have the backend check.

 

Instead use, 

 

 

fieldname.adderror('Error name');

 

in Apex Code to add error on the field.

TehNrdTehNrd

BeeddiskShah wrote:

Why is it that we need to write a separate JS for the function? Can't you just make the field free flowing and no have the backend check.

 

Instead use, 

 

 

fieldname.adderror('Error name');

 

in Apex Code to add error on the field.


If you have fields with the attribute required="true" and they are not filled in apex is never executed. 

rtuttlertuttle

Jason,

 

I think he means why not disable all of them and only use Apex to validate the fields. Seems tedious for something you could whip into jQuery with very minimal code.

 

 

-Richard 

TehNrdTehNrd

The only reason is becuase I don't want to maintain 25 if statements.

 

I'm still currently debating on whether to use a hybrid approach with Required="true" for inputFields and javascript for other inputs or javascript for everything.

Message Edited by TehNrd on 01-27-2010 09:02 AM
saharisahari

Hi

 

I have the smae problem. But my form has only four required fields. So I would 'nt mind getting this solved with apex.

But even tha apex does't seem to work. I would appreciate if anybody help me write this small apex code to validate a field.

I am not getting how to validate a fied.

I am capturing the field value in a string in the controller.

And I have written the following validation:

 

if(email==' ')

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Email is required field'));

 

Need help with this ASAP.

Thanks in advance.