How do I override CRUD tags in Play! Framework 1.2

2019-07-26 03:23发布

I've got a Model with a Many-To-Many relationship and have applied the CRUD module to it, so I get a nice multi-select box rendered on the admin screen, but it's only 4 lines high. I want to specify at least 20 lines but because CRUD is all auto-generated by reflecting the object (I guess...), even overriding the template doesn't allow for this.

The code I need to override is in views.tags.crud/relationField.html - I just want to add a "size" value like this :-

<select id="${field.id}" name="${pName}" multiple="yes" size="20">

but it doesn't seem overridable.

Anyone got any tricks to getting round this?

2条回答
等我变得足够好
2楼-- · 2019-07-26 04:17

You could use a JQuery script on load to alter the form...

查看更多
冷血范
3楼-- · 2019-07-26 04:23

You can first override the show and blank templates for the controller.

Then, declare the form fields explicitly inside the template, like this:

#{crud.form fields: ['field1','field2','field3'] /}

Leave your special case field out of the list. Then, after the form tag, add the necessary HTML for your field in any way you like. (You can look at how the field would be constructed in relationField.html and only make the necessary changes.)

It's a bit hacky but nevertheless a decent way to achieve what you are after. Hope this helps!

http://www.playframework.org/documentation/1.2.4/guide7#aCustomizingthePostforma

查看更多
登录 后发表回答