IS_ACTIVE = (
(0,'Inactive'),
(1,'Active'),
)
class Pagerule(models.Model):
pagehash = models.CharField(max_length=32,editable=False)
is_active = models.BooleanField(blank=False, choices=IS_ACTIVE, default=0)
page_type = models.CharField(max_length=1, choices=PAGETYPE, blank=False, verbose_name="Page Type")
When a Pagerule is saved, the choice on IsActive field gets through correctly as 1 for Active and 0 for Inactive but on being re-opened, the drop-down seems always pointing to the first entry in IS_ACTIVE i.e. Inactive, irrespective of the corresponding is_active value in DB.
Turned out to be matter of type-mismatch.
IS_ACTIVE = (
(False,'Inactive'),
(True,'Active'),
)
is_active = models.BooleanField(blank=False, choices=IS_ACTIVE, default=False)
Related
I created a one Login Form in the bright script. It's following
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TextBox 1 ' Here the focus is active I set by default in TextBox field active = true
TextBox 2 ' Here the press down key to active true
Button 1 ' Here again press down key to focus true
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Here, I maintain the 3 Items using 3 different key. Now I want to maintain the single key for all 3 items using the down key. Anyone idea to How to maintain Focus using Brightscript.
I used the one function for key handling It's here
function onKeyEvent(key as String, press as Boolean) as Boolean
.................
end function
Now, I maintained the key like
I set TextBox Focus active in ByDefault to XML File.Now I apply Logic to below.
First item focus set on XML file by default.
if key = "down" then
'Here Second item focus
m.keypass.active = true ' Here work successfully First time
if key = "down" and m.keypass.active = true and m.btnsub.active = false then
'Here not maintain successfully its directly call here I press the down key.
m.keypass.active = false
m.btnsub.active = true 'Here third item focus is not maintained
end if
end if
I first-time press the down key It's working fine But its second time How handling the Focus. I used the same thing in Up key.
Here I am using "and" then the issue will happen is there any idea.
Pls, Check Here's an image really what I want to do.
Edited Post:
I handle with up and down key with below code. It's working But, Its only work in a single time.
if key = "up" or key = "down"
if key = "down"
?"here down key"
if m.keypass.id = "instructpass" and m.keypass.active = true
? "down key if part"
m.btngrp.setFocus(true)
m.keypass.active = false
handled = true
else if m.keyid.id = "instructid" and m.keyid.active = true
?" down key else part"
m.keypass.active = true
m.keyid.active = false
handled = true
else if m.btngrp.buttonSelected = 0
m.keyid.active = true
m.btngrp.setFocus(false)
handled = true
end if
handled = true
else if key = "up"
? "here up key"
if m.keypass.active = true
?"up key if part"
m.keyid.active = true
m.keypass.active = false
handled = true
else if m.keyid.active = true
?"id key"
m.btngrp.setFocus(true)
m.btngrp.focusButton = 1
m.keyid.active = false
handled = true
else if m.btngrp.focusButton = 0 and m.btngrp.buttonSelected = 0
?"up key else part"
m.keypass.active = true
m.keypass.setFocus(true)
m.btngrp.setFocus(false)
handled = true
end if
handled = true
end if
handled = true
end if
Thank you.
Check here.
You should use .setFocus(true) and .hasFocus(), which are available to most renderable nodes such as TextEditBox and Button.
E.g.
if key = "down" then
if textBox1.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
button.setFocus(true)
end if
end if
if key = "up" then
if button.hasFocus() then
textBox2.setFocus(true)
elseif textBox2.hasFocus() then
textBox1.setFocus(true)
end if
end if
I have a stock model and supply model and stock belongs to supply model.
I want to sort stock records based on "date_received" attribute of supply model
Stock.where("seller_id = ? AND status = ? AND product_id = ?", #seller_id, "Approved", list_item.product_id)
I am getting error for below:
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", #seller_id, "Approved", list_item.product_id).order("supply.date_received")
there just should be supplies instead of supply Try,
Stock.includes(:supply).where("seller_id = ? AND status = ? AND product_id = ?", #seller_id, "Approved", list_item.product_id).order("supplies.date_received")
I have the ID of a record I would like to update, However I would only like to edit just one field in this record.
I would like to change the "Availability" field value in the "Vehicles" table from True to False.
How can I go about doing this without changing any other values?
I am using the code first approach and vehicleID holds the Id of the record I want to edit in the "Vehicles" table
var vehicleID = db.RentalAgreements
.Where(x => x.rent_agree_no == merchant_reference)
.Select(x => x.vehicle_id)
.Single();
var d = db.RentalAgreements.Where(x => x.rent_agree_no == merchant_reference).Select(x => x.vehicle_id).Single();
var vehicle_record = db.Vehicles.FirstOrDefault(p => p.vehicle_id == Convert.ToInt32(d));
vehicle_record.Availability = false;
db.SaveChanges();
The page that I'm working on involves a table and datepicker. If I change the value of the date, it should pass the date to the index action and re-query from DB. And display the newly queried data from DB. In other words, datepicker serves as a filter.
I made a change event for the datepicker, if the data is changed this will trigger an ajax call to index. It was able to get the correct data but could not display it properly. Grails returns the whole page. It does not update the page.
Here's my controller:
def index() {
def currentCompany = sessionService.company
def Long countryId = params.countryId ? params.countryId as Long : currentCompany.countryId;
java.text.DateFormat format = new java.text.SimpleDateFormat("dd/MM/yyyy");
Date startDateValue = (params.startDate == null || params.startDate.isEmpty() ) ? null : format.parse(params.startDate)
Date endDateValue = (params.endDate == null || params.endDate.isEmpty() ) ? null : format.parse(params.endDate)
def exchangeRateList = exchangeRateService.getFilteredExchangeRate(countryId, startDateValue , endDateValue)
def currencyList = cacheService.currencies
params.max = 10
params.countryId = countryId
respond ("", model : [
exchangeRateInstanceList : ListUtil.list(exchangeRateList, params),
exchangeRateInstanceCount : exchangeRateList.size(),
currencyInstanceList : currencyList
]);
}
Could you tell me how to trigger call to index action when input test is changed using Grails?
You can use remoteFunction to run action from controller: http://grails.github.io/grails-doc/2.4.4/ref/Tags/remoteFunction.html
How can i apply validation in admin on various fields when they are dependent on each other ?
e.g. Let say in i have a Field A(BooleanField) and Field B (CharField) what i want to do is if in admin user select the Field A(checkbox) and does not enter anything in Field B
and if he tries to save ,it should throw an error like a normal blank=False gives. So how can i do this kind of validation in admin .
E.g Use Case
I have a table having the following structure :-
INTERVIEW_TYPES = (
('default', 'None'),
('Paired Visit','Paired Visit'),
('Time Series', 'Time Series'),
),
class Interview(models.Model):
ic_number = models.CharField(verbose_name ="Visit Configuration Number",max_length=20,unique=True,null =True,blank=True)
ic_description = models.TextField(verbose_name ="Visit Configuration Description",null = True,blank=True)
title = models.CharField(verbose_name ="Visit Configuration Title",max_length=80,unique=True)
starting_section = models.ForeignKey(Section)
interview_type = models.CharField(verbose_name = "Mapped Visit",choices=CHOICES.INTERVIEW_TYPES, max_length=80, default="Time Series")
select_rating = models.CharField(choices=CHOICES.QUESTION_RATING, max_length=80, default="Select Rating")
view_notes = models.CharField(choices=CHOICES.VIEW_NOTES, max_length=80, default="Display Notes")
revisit = models.BooleanField(default=False)
.....and so on ......
class Meta:
verbose_name = 'Visit Configuration'
verbose_name_plural = 'Visit Configurations'
# ordering = ('rpn_number',)
def __unicode__(self):
return self.title
Its admin.py
class InterviewAdmin(admin.ModelAdmin):
list_display = ('id','title', 'starting_section','ic_number','show_prior_responses')
raw_id_fields = ('starting_section',)
admin.site.register(Interview, InterviewAdmin)
In admin , If i select the checkbox of revisit and in the field interview_type(which will show a dropdown having choices None,Paired Visit , Time Series) if a User has selected None from that dropdown and then press save button it should throw me an error like a normal blank=False shows, saying "This field is required"
How can i do this kind validation where fields are dependent on each other ?
Please Ignore syntax error is any .
Thanks
I got confused in response_change and overriding clean method finally this is what i did
override clean method by making a model form in admin.py
class InterviewAdminForm(forms.ModelForm):
class Meta:
model = Interview
def clean(self, *args, **kwargs):
cleaned_data = super(InterviewAdminForm, self).clean(*args, **kwargs)
if self.cleaned_data['interview_type'] == "default" \
and self.cleaned_data['Revisit'] == True:
raise forms.ValidationError({'interview_type': ["error message",]})
return cleaned_data
class InterviewAdmin(admin.ModelAdmin):
# call the form for Validation
form = InterviewAdminForm
#....and so on ....