Rich text plugin for Grails - grails

I know that there are already richtext plugins for grails like RichUI, CKEditor, FckEditor etc, but is there any plugin which binds itself with grails so well that when I can use a rich textbox just by specifying widget attribute under the constraints clause
Example
static constraints = {
dateCreated display:false
lastUpdated display:false
question nullable:true, widget:"richtext"
}

I don't know of such a feature, but I guess you can solve this by yourself:
use install-templates to get the scaffolding (and generate-all) templates http://grails.org/doc/latest/ref/Command%20Line/install-templates.html
you'll find a file called renderEditor.template and in this a method called renderStringEditor
there you'll find how to render the input tag based on the value of the widget constraint
Would be a nice addition to the existing plugins.
btw: FckEditor seems to be a little bit old and I guess CKEditor should be used instead.

Related

How to customize grails field plugin

How can I customize the template of my field plugin? how to apply bootstrap classes to it?
Where can I get the default template of a f:field (for example) to customize it ?
Thank you
You can check documentation of grails field plugin, I think is very clear Grails Field Plugin Custimization Page
In resume, you have to create gsp file templates, for the diferent fields, it can be done by varios options for example property type, propery name, controller, action, etc. In those template files you can apply the bootstrap clases you want to use.

multi line tag in grails or html

With a grails app and from a local database, I'm returning some text in a xml format.
I can return it well formed in a <textarea></textarea> tag with the correct indenting (tabulation, line return,...etc.)
I want to go a bit further. In the text I'm returning, there are some <img/> tags and I'd like to replace those tag by the real images themselves.
I searched around and found no solution as of now. I understood that you can't add an image to a textarea (other then in a background), and if I choose a div tag, I won't have the indenting anymore (and therefore, harder to read)
I was wondering if using a <g:textField/> or an other tag from the grails library will do the trick. And if so, How can I append them to a page using jquery.
For example, how to append a <g:textField/> in jquery. It doesn't interpret it and I get this error
SyntaxError: missing ) after argument list [Break On This Error]...+doc).append("<input type="text" id="FTMAP_"+nb_sec+"" ...
And in my javascript file, I have
$("#FTM_"+doc).append("<g:textField id='FTMAP_"+nb_sec+"' ... />
Any possible solutions ?
EDIT
I did forget to mention that my final intentions are to be able to modify the text (tags included) and to have a nice and neat indentation so that it is the easiest possible for the end user.
You are asking a few different questions:
1. Can I use a single HTML tag to include images inside pre-formatted text.
No. You will have to parse the text and translate it into styled text yourself.
2. Is there a tag in the grails standard tags to accomplish this for me?
No.
3. How can I add grails tags from my javascript code.
Grails tags are processed on the server-side, and javascript is processed on the client. This means you cannot directly add grails tags via javascript.
There are a couple methods that can accomplish the same result, however:
You can set a javascript variable to the rendered content of a grails tag. This solution is good for data that is known at the time of the initial request.
var tagOutput = "${g.textField(/* etc */)}";
You can make an ajax request for the content to be added. Then your server-side grails code can render the tags you need. This is better for realtime data, or data that will be updated more than once on a single rendered page.

Editable select/combobox

is there any way (or plugin) to display editable combobox? I have a set of options, but I would like to give possibility to enter custom value.
I've searched the documentation, and I can't find way to do this. I made workaround with javascript, but I'm looking for more elegant solution.
I'm pretty sure that there simply is no HTML form element that does this, and so Rails can't provide you with a helper. As you said, you can work with JS to create something similar (and there should be JS libraries/plugins already out there), or you could just use a select element and add a text field next to it for new values.
HTML5 specification doesn't define such an element. So you may either continue using JS, either try to use autocomplete feature of an input element (although it is not exactly what you want and doesn't compatible with old browsers).

Symfony doctrine:generate-module custom theme: cannot find templates for i18n embedded field

I generated a custom theme by copying
plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/default"
into
plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/mytheme1"
I changed the templates to match my needs (no tables, custom errors display and so on).
./symfony doctrine:generate-module --theme=mytheme1 frontend user User
works as I expected however if I add
$this->embedI18n(array('en','fr'));
to the form class the generator renders the I18n embedded form with and .
Where do this come from? How can I customize it? where are the template files for i18n embedded forms located?
Thanks a lot,
Massimo
Firstly it's not the best idea to overload a theme in the plugin itself. Plugin's shouldn't be touched to allow future updates. You can easily overload the theme in your application.
Secondly something seems to be missing in your post: "to the form class the generator renders the I18n embedded form with and ."
Maybe missing translation indicators are shown?
The template is defined in the formatter of the widgetSchema of your i18n form. By default, it is set to sfWidgetFormSchemaFormatterTable which contains the definition of what you are looking for :
class sfWidgetFormSchemaFormatterTable extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = "<tr>\n <th>%label%</th>\n <td>%error%%field%%help%%hidden_fields%</td>\n</tr>\n",
$errorRowFormat = "<tr><td colspan=\"2\">\n%errors%</td></tr>\n",
$helpFormat = '<br />%help%',
$decoratorFormat = "<table>\n %content%</table>";
}
You can change this by editing your i18n form class initialization. For example, if you want to display the fields in a list :
public function setup()
{
parent::setup();
$formatter = new sfWidgetFormSchemaFormatterList($this->getWidgetSchema());
$this->getWidgetSchema()->addFormFormatter('list', $formatter);
$this->getWidgetSchema()->setFormFormatterName('list');
}
You can also define your own formatter inheriting from sfWidgetFormSchemaFormatter to match your layout preferences.

customizing form templates (new/edit view) for admin generated modules

I am using SF 1.2.9 (with Propel ORM), to build a website. I have generated admin modules for some of my models. I want to modify the template used to display the Form because there are some fields that I dont want to display (but need) - example the 'slug' field in a form.
Since the templates are autogenerated, I cant make the changes there. How can I specify a template to use for rendering a form in the new/edit view?
In general, to override generated templates with your own, you just have to name your template same as generated one.
But looks like you do not need it. Hint: you can choose which fields to show in admin generator. Please consult symfony reference manual to realize how
To hide or remove fields from a form, I think you should check that link.
To sum up, the admin generator uses a ORM sfForm to render the edit action. So if you remove fields:
// lib/form/doctrine/ADoctrineClassForm.class.php
class ADoctrineClass extends BaseADoctrineClass
{
public function configure()
{
...
unset($this['field_name']
...
You can also change the widget used the render the field by redefining which widget to use:
//in ADoctrineClass configure method also
$this->widgetSchema['a_field_a_want_to_hide'] = new sfWidgetFormInputHidden()
I hope this helps.

Resources