Joomla JHTML Grouped buttons - list

Im trying to bild a joomla component where the user can choose two options (for example yes/no).
Joomla has the possibility to add grouped buttons through an XML file with radio & class "btn-group btn-group-yes-no". However it is also possible to add a form list through JHTML: JHTML::_('select.genericList', $publish, 'published', ' class="inputbox" '. '', 'value', 'text', published)
I can't find it anywhere on the internet, so i think its impossible through JHTML. I want to add a btn-group through JHTML...
Thanks for your effort!
Ron

If you're trying do it for Joomla! 3.x you should just write at the XML file like this:
`<field name="enable_quantity" type="radio" class="btn-group" default="0"
label="Enable quantity"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>`
It's valid with using JForm editing model.

Related

Opencart language switcher

I'm trying add a new language to opencart version 2.1.0.2. I've uploaded the language files and added the new language via localization->languages. Administration language works fine however the site language only changes when default language is set trough admin panel. language drop down menu does not change the site language. Anyone can help?
thanks in advance
I've solved the issue:) It appears somehow i broke the form in the catalog/view/default[or your theme]/common/language.tpl file (i've added some css and javascript files manually).
For anyone encounter a similar issue, you need to be sure that the form in the language.tpl file
(<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="language">)
posts the hidden input field (<input type="hidden" name="code" value="" />)
with the value of the language code that is taken from the href atribure of the a tag within the dropdown list
<a href="<?php echo $language['code']; ?>">
I'm not writing the exact way i solved the issue because it is far too messy to suggest someone else to use it:) but basicly with some javascript (even better with jquery) you need to assign the value of href attribute of the a tag to the value attribute of the hidden input field
if your language switcher does nothing or give you a page not found error or an internal server error you might have a similar issue

Ember: Is there a way to pass a model through a select dropdown?

I am creating a dropdown menu which is populated with cities. When a user selects a city from the dropdown, I would like to pass a city model to my "selectChange" action handler. The problem is that the model is always passed as a string:
<select class="{{b}}__select" onchange={{action "selectChange" value=target.value}}>
{{#each itinerary.cities as |city|}}
<option value={{city}}>
{{city.name}}
</option>
{{/each}}
</select>
I could pass the id and then fetch the model from that, but if I could just get this working it would be so much easier. Thanks!
Unless something changed a lot in Ember in the last versions, its select tag support it's pretty poorly.
I recommend you to take a look at some Ember select addon, like ember-power-select or emberx-select.
I think the first one is the most popular.

Getting dropdown value from template django

I am facing an issue working with django ( using shopcart ). I want to add a select options field to change dynamically an item suscription in the cart, but I am not getting the value selected from the template.
In my template where I display the cart I have :
<form action="" method="GET">{%csrf_token%}
<select name="suscr" title="suscr">
<option value="" selected>Suscribe</option>
<option value="1" name="suscr" >Weekly</option>
<option value="2" name="suscr">Monthly</option>
</select>
</form>
I want to select an option and then, if I press 'Checkout' to have the cart updated.
Appart from that, I believe its missing a method modifying the item in cart.py.
Any ideas would help.
Thanks
The above form is inside a loop
{% for item in cart %}
What i propose you to do is not python-oriented but all javascript for the most part as, from the description, we assume that what you are dealing with is going all at the client-side.
As you are dealing with a shopping cart, what i'd do is storing what the user is checking in a sessionStorage so that the information would persist while the user navigates through your website even with multiple tabs. As the user might just be "walking around" you shopping website, there's no need to push things to the database without even knowing if the user wants that. Just remove the form and keep with the select, then you get what the user selected appending an attribute to select: <select onchange=my_function(this.value)>...</select> and then, inside my_functionin a script change whatever you want to the page.
When the user enters the shopping cart page you show him what he selected so far getting the items from the sessionStorageand then, if he/she confirms that wants to buy, then submit a form to the server-side, update the database and proccess that as your workflow states.
tl;dr: store the options in sessionStorage, just post to the server at the end.
For help on the server-side update your question with more info about the cart.py

Using Bootstrap wysiwyg text editor in Django Form

I am using Django and Bootrap 2.32. I want to include this wysiwyg-bootrap-themed text editor: http://mindmup.github.io/bootstrap-wysiwyg/. The usage of this editor is fairly simple, including
$('#editor').wysiwyg();
in the JS-declaration will render each
<div class=editor></div>
into a beatiful wysiwyg text-editor.
Now the problem: I want to include this editor into one of my django form field. I have the single form:
class Article_Form(ModelForm):
Article_text = CharField(widget=Textarea(attrs = {'id' : 'editor'}))
class Meta:
model= Article
, whereas the Article model includes one simple CharField . Is there any chance, to get the editor work inside the Article_text form-field? With the above-mentioned widget, the created textarea cannot be controlled by the wysiwyg-editor-control buttons. Wrapping the form-template-tag like this
<div id="editor">
{{ Article_Form.Article_text }}
</div>
doesn't work either. The problem thus is that Django creates a textarea, wheras the editor would need a <div> to render correctly. Do you guys have any idea how to get this to work (without refering to django-wysiwyg).
Thanks!
I don't know enough about Django but I wrote the editor you're referring to, so here's a suggestion. Assuming the other answer on this page is correct and you can't generate a div directly, you can generate a text area using whatever Django templates you would normally do, then assign two events:
1) page onload event that would copy the textarea contents into the div, something like
$('#editor').html($('#textarea').val())
2) form onsubmit event that would reverse copy the current div contents into the textarea before it gets submitted
$('#textarea').val($('#editor').html())
Take a look at this.
Summernote is a simple WYSIWYG editor based on Twitter's Bootstrap.
django-summernote plugin allows you to embed Summernote into your Django admin page very handy.
https://github.com/lqez/django-summernote
Are you sure that this "plugin" doesn't work with textarea?
{{ Article_Form.Article_text }}
will be rendered to something like:
<textarea cols="40" id="id_Article_text" name="Article_text" rows="10"></textarea>
So there is a chance that you can initialize the wysiwyg editor like:
$('#id_Article_text').wysiwyg();
However after checking the plugin, I doubt that would be possible since it is using contenteditable="true" attribute of HTML5 and probably the plugin works with div only.
So there is no way you can make it work natively with Django form. The solution should be display other fields of your form manually, hide the one with textarea and display the editor instead:
<form action="" method="POST">
{{ Article_Form.field1 }}
{{ Article_Form.field2 }}
<div class=editor></div>
{% csrf_token %}
<input type="submit" value="Submit" id="submit-btn" />
</form>
Then you can use JS to submit your form:
$('#submit-btn').click(function (e) {
e.preventDefault();
$.ajax({
// do your magic here.
// note that you can get the content of the editor with: $('#editor').cleanHtml();
})
});
This way is hackish I agree so I don't recommend you go for it, just find other plugin then. Also please read PEP 8 carefully.
Hope it helps.
Take a look at this repo: https://github.com/rochapps/django-secure-input
I think it solves most of your problems.

storing array injoomla 2.5 component development

I am developing a Joomla 2.5 component. So I'm using Hello world example component for reference... In the edit view of the admin back end
<?php foreach($this->form->getFieldset('details') as $field): ?> <div>
<?php echo $field->label; echo $field->input;?> </div>
where the array $this->form->getFieldset('details') is stored.. and how to add new fields to the form that will store the data to another database table. where to change the fielda of the forms.
If you need to add more fields in your form then you can add new field in to the helloworld.xml browse to the following file on to
administrator->components->com_helloworld->models->forms->helloworld.xml
Open this file you will find the number of fields are listed over there you can add your own field by copy any of the field and rename it as you want.
You can also refer this link : J2.5:Developing a MVC Component/Adding backend actions
For example you want to add description field on to your form then you just need to add this line between the fieldset tag.
<field
name="description"
type="text"
label="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_DESC"
size="40"
class="inputbox"
default=""
/>
I would prefer you first read full tutorial of how to create MVC component for Joomla.Then you would be able to know how it works. Here the link :
J2.5:Developing a MVC Component/Developing a Basic Component
You may also use different form field type : Form field