سؤال

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