I have a Joomla fields form like this:
<field
name="visible"
type="list"
label="COM_VISIBLE"
description="COM_VISIBLE_TOOLTIP"
class="inputbox">
<option value="0">COM_HIDDEN</option>
<option value="1">COM_VISIBLE</option>
</field>
How to get class properties??
$field->label and $field->input it's ok...
but with
JFormFieldList
JFormFieldMedia
JFormFieldHidden
JFormFieldMedia
return "Undefined property: JFormFieldList::$class in... ()"
Otherwise it's empty
SOLVED
$class = $this->form->getFieldAttribute($field->fieldname, 'class', '', $field->group); –
Related
My ticket has many comments and I created a view for my comment and make a One2Many field in ticket model. But it is not displaying my desired view. Here is my model
class Ticket(model.Model):
_name = 'Tickets'
comment_ids = fields.One2many('comments', 'comment_id')
Here my second model
class Comments(models.Model):
_name = 'comments'
comment = fields.Text(string="Comment")
comment_id = fields.Char(string='Comment Id')
Here is my Ticket's View:
<notebook>
<page name="body" string="Body">
<field name="comment_ids" />
</page>
</notebook>
Here is my Comment's Form View:
<form>
<div class="form-group">
<label name="comment">Comment:</label>
<textarea class="form-control" rows="5" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Here is my Comment's Tree View:
<tree>
<field name = 'comment_id'/>
<field name = 'comment'/>
</tree>
If your comment model have more than one tree view or form view, if you don't specify
witch view you want to display Odoo will compute the one with the highest priority:
so just specify the id of the tree view in your one2many field
<field name="comment_ids" context="{'tree_view_ref': 'your_app.tree_view_xml_id', 'form_view_ref': 'your_app.form_view_xml_id'}"/>
Or you can use embedded view:
<field name="comment_ids">
<tree>
<field name = 'comment_id'/>
<field name = 'comment'/>
</tree>
<form>
<div class="form-group">
<label name="comment">Comment:</label>
<textarea class="form-control" rows="5" />
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</field>
Note: if you have only this two views this means that Odoo didn't load this views so check if the XML file is in the manifest file and make sure you upgrade your module.
how one can assign class="some_class" to option in select box?
i would like to have
<select class="my_class" name="example">
<option selected="selected" value="">Choose something ...</option>
<option value="1" class="some_class">Hello</option>
<option value="2" class="some_class">World</option>
</select>
But I don't have any idea how to do it.. my form looks like:
{{ Form::select('example', array('1' => 'Hello', '2' => 'World'), null, array('class' => 'my_class', 'placeholder' => 'Choose position ...')) }}
How can I add "some_class" attribute to OPTION menu ?
The Form builder doesn't support class attributes for option tags. You will either need to build the select manually, or use JavaScript / jQuery to add the class to the option tags.
You can use my_class similar to this:
.my_class select option{
font-size: 20pt;
color:red;
}
This will affect only <option> elements of your <select> element.
Also, you can use JS to do this.
What is the best way to construct a html5 datalist with mojolicious?
I looked for a tag helper but did not find a tag helper for constructing it.
Here is an example of a datalist:
<datalist id="frameworks">
<option value="MooTools">
<option value="Moobile">
<option value="Dojo Toolkit">
<option value="jQuery">
<option value="YUI">
</datalist>
The list is dynamic and is fetched from a db, so i cannot use a static html chunk.
There are similar tag helpers, e.g. for a <select> tag I can put into my template:
%= select_field country => [[Germany => 'de'], 'en']
which produces:
<select name="country">
<option value="de">Germany</option>
<option value="en">en</option>
</select>
but I couldn't find anything regarding a datalist in the default tag helpers.
It's been a while, but maybe will find it useful.
In the controller, you need to have an array with some items. Let's create it:
my #levelsArray = ();
for (my $i=0;$i<10;$i++){
push #levelsArray, "level00".$i;
}
After that, send it to the template:
get '/index' => sub {
my ( $mojo ) = #_;
$mojo -> stash ('levelsArray' => \#levelsArray);
$mojo -> render (template => 'index' );
};
and finally, render it using:
<%= select_field 'levelSelected' => [ #{ stash('levelsArray') }] %>
I'm not sure how this is mojolicious specific, but wouldn't simple html in your template would be enough:
<datalist id="frameworks">
<option value="MooTools">
<option value="Moobile">
<option value="Dojo Toolkit">
<option value="jQuery">
<option value="YUI">
</datalist>
<input type="text" list="frameworks" />
EDIT
Let me clarify, this wouldn't be static HTML in your template...you would fetch your data within controller and pass that data to template which would construct this kind of HTML with it's templating engine.
Is there a way to map the data inside a map to tag?
I have a map Map<String, Integer> in my code.
Is there a way to map the option labels to the String in the map and the Integer to the option values?
The <form:options> tag supports what you want right out of the box, using the items attribute. You can do something like this:
LinkedHashMap<Integer, String> states = new LinkedHashMap<Integer, String>();
states.put(1, "Alabama");
states.put(2, "Alaska");
states.put(3, "Arizona");
states.put(4, "Arkansas");
states.put(5, "California");
And so on. Then in your form:
<form:select path="state">
<form:options items="${states}" />
</form:select>
That will be rendered to something like:
<select name="state">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
<option value="5">California</option>
</select>
See the Spring form:select and form:options documentation. Use items, itemValue, and itemLabel as needed.
<form:select path="myFormVariable">
<form:option value="0" label="Select One" />
<form:options items="${myCollection}" itemValue="propertyToUseAsValue" itemLabel="propertyToUseAsDisplay" />
</form:select>
Before:
<input type='checkbox' name='killerFeature' id='killerFeature'
<%= param('killerFeature') ? ' checked' : ''%>
/>
Now:
<select name="killerFeature" id="killerFeature" class="select">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
How do I insert the same checked (should be 'selected' now I guess?) condition in the select now?
This is a perl app, built using Mojolicious web framework.
Many thanks for your help!
Yes, the condition should be selected (selected="selected") but i belive you already figured that out from your other post :)
<select name="killerFeature" id="killerFeature" class="select">
<option value="1" selected="selected">Enable</option>
<option value="0">Disable</option>
</select>
Also from what i saw there inst a way to create the select like you can for the input as in the below example:
<%= input 'test', type => 'text' %>
So it would be something like:
<%== param('killerFeature') eq $my_var ? ' selected="selected"' : ''; %>
Ofc you would need to replace the above to your current variables and field names.
GL:)