I have one question. I just want to be sure when i set some value in request variable whitout storing in database to not lost that value. This work fine but what if i come after 10 days that value stay or will be removed?
Ok simple example with option field:
<field name="bg" type="list" label="Set Background">
<option value="1"> Black </option>
<option value="2"> Red </option>
<option value="3"> Green </option>
</field>
What i want say: When in administration i set in list Black background of current element is changed.
But what is confused? That value is not stored in databas.Can I lose the current value if it is not stored in the database.
This now work fine. But where joomla store that value? memory:memory?
I just want to be sure that the value does not change. Bcs is faster whitout database
Its simply make model
// Get Background
public function getBackground()
{
if(!isset($this->bg))
{
$bg = JFactory::getApplication()->input->get('bg', 1, 'INT');
switch($bg)
{
case 1: $this->bg = 'black'; break;
case 2: $this->bg = 'red'; break;
case 3: $this->bg = 'green'; break;
default: $this->bg = 'white';
}
}
return $this->bg;
}
And view render
<h1 style="background:<?php echo $this->bg;?>"> <?php echo $this->msg;?> </h1>
Related
I have a simple django dropdown form. I want to grab the text instead of the value.
<select name="doctors" required="" id="id_doctors">
<option value="" selected="">---------</option>
<option value="3">sometext</option>
</select>
On selection I want to use the some text in the backend.
if 'bookAppointment' in request.POST:
print(request.POST['doctors'])
print(int(request.POST['doctors'])-1)
print(Profile.objects.filter())
this prints out the value 3 is there a way to just get some text out.
3
2
<QuerySet [<Profile: some>, <Profile: some>, <Profile: some text>]>
I set it up like so:
bookAppointment = BookAppointmentForm()
# Make sure I get active doctors and doctors who have a refresh_token
bookAppointment.fields['doctors'].queryset = Profile.objects.filter(Q(is_active=True)&Q(is_doctor=True))
context['bookAppointment'] = bookAppointment
Just change the value to your text, that way the text is passed through to POST instead of the value.
Otherwise you will need to add in some controls:
if self.request.POST['doctors'] == 3:
my_var = "sometext"
I'm trying use input with datalist in a lightning component and doesn't seem to work. I've looked around and can't seem to find anything that says i can't. So basically,
<input list="acctlist"/>
<datalist id="acctlist">
<option value="somevalue">
</datalist>
does not work. I want to have an input in a form that a user can type but also able to select from a list returned from the controller. Is there a workaround that would be as simple or is this the following route the best i got.
https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-lightning-inputlookup-missing-component.html
The list attribute of input tag is not compatible with lightning component.
When you deploy the components, the attribute is removed.
If you want to use input with datalist, you need to add the attribute in Renderer.js.
datalist.cmp
<input aura:id="acctlistInput" />
<datalist id="acctlist">
<option value="somevalue" />
</datalist>
datalistRenderer.js
afterRender : function(component, helper) {
var acctlistInputCmp = component.find("acctlistInput");
var acctlistInput = acctlistInputCmp.getElement();
acctlistInput.setAttribute("list", "acctlist");
return this.superAfterRender();
}
Can i write ng-repeat to iterate through the choices in a Django model field and display them? How can i do it? Should I make a separate API for this or what?
APPROVAL_CHOICES = (
(u'Good condition', u'Good condition'),
(u'Bad condition', u'Bad condition'),
(u'Broken', u'Broken'),
)
status = models.CharField(max_length=20, choices=APPROVAL_CHOICES)
I have something like the following, but it's not working:
<label>Statuss</label>
<select>
<option value="" selected>--Please select Inventory statuss--</option>
<option value="inventory.status[0]" >Good Condition</option>
<option value="inventory.status[1]" >Bad Condition</option>
<option value="inventory.status[2]" >Broken</option>
</select><br/>
And here is my API:
objects: [
{
category: {},
count: 1,
created: "2014-02-24T16:07:12.903555",
description: "Car description for image",
id: 1,
location: "IT nodala",
name: "Baterija AA",
resource_uri: "/api/v1/inventory/1",
slug: "baterija-aa",
status: "Good condition"
},
using ng repeat like this
'<select data-ng-model="selectedField">' +
' <option data-ng-repeat="v in choices" value="v">v</option>' +
'</select> ' ;
I guess your question is about how to use select tag with angular js you can use the ngOption directive.
From the AngularJS docs:
ngOptions
The ngOptions attribute can be used to dynamically generate a list of elements for the element using the array or object obtained by evaluating the ngOptions comprehension_expression.
When an item in the menu is selected, the array element or object property represented by the selected option will be bound to the model identified by the ngModel directive.
...Note: ngOptions provides an iterator facility for the element which should be used instead of ngRepeat when you want the select model to be bound to a non-string value. This is because an option element can only be bound to string values at present.
with this jsfiddles:
<body ng-app="demoApp">
<div ng-controller="DemoController">
<div>
<h2>Incorrect</h2>
<p>
We might expect the select box to be initialized to "two,"
but it isn't because these are two different objects.
</p>
<select
ng-model="incorrectlySelected"
ng-options="opt as opt.label for opt in options"
>
</select>
The value selected is {{ incorrectlySelected.value }}.
</div>
<div>
<h2>Correct</h2>
<p>
Here we are referencing the same object in <code>$scope.correctlySelected</code>
as in <code>$scope.options</code>, so the select box is initialized correctly.
</p>
<select
ng-model="correctlySelected"
ng-options="opt as opt.label for opt in options"
>
</select>
The value selected is {{ correctlySelected.value }}.
</div>
</div>
</body>
Check the docs form more exmaples.
How do I add a "none" option to the play framework select field?
So far, I have this:
<select size="1" name="object.id">
<option value="">&{'crud.none'}</option>
#{list items:someItems, as:'item'}
<option value="${item.id}">${item.name}</option>
#{/list}
</select>
but when i select the "none" value, play constructs a new object, and tries to save the parent object with a reference to the newly created object, resulting in a hibernate org.hibernate.TransientObjectException
Any ideas?
Set none option's value to 0 and in your controller add relation only in case if (item.id > 0)
<option value="0">&{'crud.none'}</option>
What's more if this value is required you can use simple check with JavaScript to ensure, that user selected some option
I'm struggling for set the 'name' attribute of a form select field with django.
This is what i'm trying :
def make_layers_form(dxf_model):
layers = Layer.objects.filter(dxf_file=dxf_model)
choices = [(m[0], m[1]) for m in settings.MACHINING_CHOICES]
fields = {}
for l in layers:
if l.name.decode() == "0":
# Si le layer 0 existe on l'associe a la "Coupe"
init = settings.MACHINING_CHOICES["CUT"]
else:
# Par défaut on met la valeur "Aucun"
init = settings.MACHINING_CHOICES["NONE"]
fields[l.name] = forms.ChoiceField(choices=choices, initial=init,
widget=forms.Select(attrs={'name':dxf_model.filename+"_"+str(l.pk)}))
return type('LayersForm', (forms.BaseForm,), {'base_fields':fields})
When I watch to the 'name' attribute, it is not set as expected...
Furthermore I try to set a default value in some case, but it has no effect. Any ideas ?
Thanks for your help!
UPDATE
Here is an html example
<select name="0" id="3_0">
<option value="NONE">Aucun</option>
<option value="CUT">Coupe</option>
<option value="MARK">Marqueur</option>
</select>
...
<select name="0" id="4_0">
<option value="NONE">Aucun</option>
<option value="CUT">Coupe</option>
<option value="MARK">Marqueur</option>
</select>
Each select tag permits to bind some datas to 2 differents files previously uploaded
The value of the attribute 'name' comes from the value of label_tag if I am not wrong.
And the value of the label_tag is a data extracted from each file respectively.
Unfortunately two differents files can contain the same value, which is extracted for setting the attribute 'name'. This is my problem!
So I would define the attribute name of each select tag as it follows:
(filename)+"_"+(the value extracted from the file)
I don't know if my explanations are clear...
Do you know why what i'm trying is not working ?
Further more when I set the initial value, it has no effects...