Crud : add ability to add custom fields in the form

Bug #507978 reported by hugo lassiège
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

Hi,

I would like to add some fields in a form that were not in the model object.
My purpose was to add some custom fields in the form. My common use case is a form to create a user. The field "confirmPassword" is not a field in the model but I would like to add it in the form (and handle it in the save method, I don't know how for the moment).

#{crud.custom 'confirmPassword'}
... some code to display the confirm password
#{/crud.custom}

Or maybe you have some other ideas ?

Tags: crud
Revision history for this message
Mardo Del Cid (mardodcp) wrote :

well... you can create a transient field, so that field will not be persisted in your database, your User model would be like this:

@Entity
public class User extends Model {

 @Email
 @Required
 public String email;

 @Required
 @Password
 @Equals("passwordConfirmation")

        //another fields...
}

-------

and your view like this:

#{crud.form}

 #{crud.custom 'password'}

  <label for="object_password">&{'password'}</label>
  <input type="password" id="object_password" name="object.password" value="">

  <label for="object_passwordConfirmation">&{'passwordConfirmation'}</label>
  <input type="password" id="object_passwordConfirmation" name="object.passwordConfirmation">

 #{/crud.custom}

#{/crud.form}

Revision history for this message
Mardo Del Cid (mardodcp) wrote :

In the coment above i ment to add the "passwordConfirmation" field like this:

@Required
@Password
@Equals("passwordConfirmation")
public String password; //<<--- forgot to add this line ^^

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.