I'm using Grails 2.3.x

Imagine the domain class: Book (String Author, String Title)

  1. When I'm creating a book I need the Author field and the Title field editable.

  2. When I'm editing a book I need the Author field NON-editable and the Title field editable

I know that there is a Domain Constraint (editable: false), but that doesn't work with the second case. It only adds this tag to the readonly="readonly"

I also tried this: How to conditionally disable a form input field But it seems that: "${mode == 'edit'}" is always false.

Thank you very much

有帮助吗?

解决方案

That link you provided assumes that a variable flag called mode will be passed into the view to determine whether you are editing or not. To do this, you will need to pass mode into the view from your controller like this:

def edit(Long id) {
    [bookInstance: new Book(), mode: 'edit']
}

That will force the ${mode == 'edit'} portion to be true.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top