View unanswered posts | View active topics It is currently August 1st, 2010, 6:28 am



Post new topic Reply to topic  [ 6 posts ] 
Marking required input fields 
Author Message

Joined: September 6th, 2009, 9:29 pm
Posts: 9
Location: Düsseldorf, Germany
Post Marking required input fields
Hi,

I want to assing a special css class to an input field when the according field in the bean is required.

I have a domain class like this

class Dummy
{
String iAmRequired
static constraints = {
iAmRequired(nullable: false) }
}

and a create.gsp where I assign values to this class like this

<input type="text" name="iAmRequired" >${fieldValue(bean:dummy, field:'iAmRequired')}</input>

Is there something like class="value ${hasErrors(bean:dummy,field:'iAmRequired','errors')}" with what I can do it?


September 8th, 2009, 3:41 pm
Profile E-mail WWW

Joined: September 5th, 2009, 2:47 pm
Posts: 17
Location: Graz, Austria
Post Re: Marking required input fields
Hi!

Maybe you can try something like this in your Controller to find out dynamically which properties have a blank constraint applied.
Collect the keys that have the constraint you want to check.

Code:
      
Book.constraints.each { key, value ->
    println key + " - " + value.hasAppliedConstraint(org.codehaus.groovy.grails.validation.ConstrainedProperty.BLANK_CONSTRAINT)
}


In the view you could probably use a nifty prototype script that adds some css class or style to your input fields.

BTW: http://jira.codehaus.org/browse/GRAILS-270 is what you need I think. Be patient and stay tuned ;)

I'm also quite new to Grails and maybe someone here knows a much more elegant solution.

kind regards,
hth,
Flo


September 8th, 2009, 4:46 pm
Profile E-mail ICQ WWW

Joined: September 5th, 2009, 2:47 pm
Posts: 17
Location: Graz, Austria
Post Re: Marking required input fields
Hi!

Maybe a little bit late but I blogged about how you can solve this problem:

http://www.caffeinated.at/2009/09/visua ... eneration/

Flo


September 17th, 2009, 7:44 pm
Profile E-mail ICQ WWW

Joined: September 6th, 2009, 9:29 pm
Posts: 9
Location: Düsseldorf, Germany
Post Re: Marking required input fields
Hi,

thanks for your answer. The Jira Issue is exactly what I need :-)
Your first post helped me, the second comes a litte late...

I solved this Problem by writing: class="required ${Dummy.constraints?.iAmRequired?.nullable}"
so I get class="required true" or class="required false"

Maybe not the best way but it works

kind regards
stormqueen


September 17th, 2009, 9:16 pm
Profile E-mail WWW

Joined: September 15th, 2009, 11:52 am
Posts: 6
Post Re: Marking required input fields
There's the bean fields plugin Marc Palmer released earlier this month:

http://grails.org/plugin/bean-fields

Might help you out a bit


September 24th, 2009, 8:25 am
Profile E-mail
Site Admin
User avatar

Joined: August 31st, 2009, 11:23 pm
Posts: 106
Location: São Paulo - Brazil
Post Re: Marking required input fields
I suggest you all use Marc`s plugin, this is an awesome functionality that IMHO, should be added to grails core.

[]s,

_________________
Lucas Frare Teixeira
lucastex at gmail.com
twitter: @lucastex
http://blog.lucastex.com


September 24th, 2009, 11:14 am
Profile E-mail ICQ WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum theme by Vjacheslav Trushkin for Free Forum/DivisionCore.