I am trying to figure out the best way to handle this. I have a series of form fields with checkboxes for people to select options. When that gets submitted it turns form.optiongroups into an array. I then check to see if the id of the optiongroup is in the array and set the checked value to true in case there were form errors I want them to retain their checked value. This all works fine.
If I only select one option though it doesn't come through as an array, but just a regular form field. Is there a way I can handle this to make sure it is always an array?
Actually, checkboxes get submitted as a list. You must have something else going on that creates the array.
However, to answer your question as asked, you can use ListToArray(). It would be something like this:
if (structkeyexists(form, 'optiongroups') { // if no boxes are checked the variable will be undefined.
if (isArray(form.optiongroups) == false )
form.optiongroups = ListToArray(form.optiongroups)
} else {
code for no boxes checked
}
It could also be done via...
param form.optiongroups = "";
form.optiongroups = ListToArray(form.optiongroups);
Related
Actually i want to read emails one by one in junk folder of "outlook:live" and mark emails "Not spam".
emails = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH,"//div[#class = 'xoCOIP8PzdTVy0T6q_uG6']")))
This xpath matches 400 instances. I want to make a loop to select one email at a time like select first email, click on the div and perform action and then 2nd email and so on. I'm trying this
emails = WebDriverWait(driver,
5).until(EC.element_to_be_clickable((By.XPATH,"//div[#class =
'xoCOIP8PzdTVy0T6q_uG6']")))
for count in range(0,len(emails)):
(emails)[count+1].click()
Please help me know where im doing wrong. Thanks in advance
It appears that the function you're using to return the clickable elements is only returning a single element, so you'll have to use a different function, make a change in your logic, etc.
For instance, you could use Selenium's find_elements_by_xpath("//div[#class = 'xoCOIP8PzdTVy0T6q_uG6']") which will return a list of WebElement object(s) if the element(s) are found, or an empty list if the element(s) is not found. This will, of course, not take into consideration the possibility of the elements not being completely loaded on the page. In my experience, just slapping a time.sleep(10) after you open the page is "'good enough".
I recommend making sure your elements can be discovered and interacted with first to make sure this isn't all in vain, if you haven't already.
Another option is to add another function, something like a elements_to_be_clickable() function, to the Expected Conditions source code.
From the Expected Condition documentation, I've done some research and it looks like the element_to_be_clickable() function only returns a single element. Moreover, from the source code, said function mainly makes use of the visibility_of_element_located() function. I believe you could follow similar logic to the element_to_be_clickable() function, but instead use the visibility_of_all_elements_located() function, in order to return multiple WebElements (since visibiilty_of_all_elements_located() returns a list of WebElements).
I have cascading select where the value in the first decided what should be the option of others.
When I change the value of the first select so that the currently selected value in one other is no more a possible choice, I get a null (empty) choice. In place, I want to get a default, not null, value (of course, I don't want to reset to a default value is the choice is still legit).
I looked to (rather) similar question like Why does AngularJS include an empty option in select? but is does not seem to work, perhaps because my options are not predefined but generated on change.
I set-up a jsfiddle with the actual code: http://jsfiddle.net/sXu9a/
choose 2 hours or greater on the first select
chosse 1 in the second select (start hour)
choose back less than 1 hour in the first select
=> the second select display a empty option, and the "startHour" model still contains the last selected value (which is no more a valid choice). I really want to update the ng-model for that option to be reseted to 0.
In fact, I would like to be able to encode the condition: "if current model value for selected option is not in the set of possible value, reassign to model a default value (0)". So I tried a "onChange" like that:
$scope.onChangeInterval = function() {
if(jQuery.inArray($scope.agentSchedule.startHour, $scope.startHours() ) ) {
$scope.agentSchedule.startHour = $scope.startHours()[0];
}
}
But that does not seem to work.
Any idea about that ?
So, it happens that the "onChange" solution DOES work, as long as you don't make typos in the variable of your name. So with the following code (onChange is called on the first select):
$scope.onChangeInterval = function() {
if(jQuery.inArray($scope.agentSchedule.startHour, $scope.hours() ) ) {
$scope.agentSchedule.startHour = $scope.hours()[0];
}
}
Sorry for the noise!
I am trying to modify the list of components displayed in the sidekick based on the user's privileges.
I am trying it as explained here.
What i would like to know is how to send back the modified allowed array that is received as the argument, because what ever modifications i make to the array appears to be in the local scope. For e.g. if i want the allowed components to consist only of the default list component, i do something like this.
function MyHandler(cell, allowed, componentList) {
allowed = [];
allowed.push("/libs/foundation/components/list");
}
But once the control goes back to the function that triggered this event, these changes are not visible. Should i be returning the array or something ? Could you please explain if i am missing something here?
Ok. Finally figured the issue. I wanted to clear the existing list of components that were passed on to my handler, for which I used allowed = [];.
This removed all the existing references to the allowed array. (More about this explained here).
Thus changing it to allowed.length = 0; works absolutely fine.
function MyHandler(cell, allowed, componentList) {
allowed.length = 0;
allowed.push("/libs/foundation/components/list");
}
I have a listbox defined in XAML and I filter its items using the following code from text obtained from a textbox:
if (list.Items.Count > 0)
{
CollectionViewSource.GetDefaultView(list.Items).Filter =
new Predicate<object>((item) => {
string valtoCheck = item.ToString();
return valtoCheck.StartsWith(filterText,
StringComparison.CurrentCultureIgnoreCase);
});
}
Everything works fine, except in the case where the filter finds no items matching the criteria.
ex. Lets say I have 4 items in the list : Rob,Bob,Andy,John.
When I enter Ro, the list filters accordingly (shows rob).
When I enter b, the list gets filtered appropriately (shows bob).
However, if i enter z (the target list becomes empty), I get an empty list which is correct; but then List.Items.Count is set to zero from that point on. The list becomes empty. I would assume that typing a replacement b should show me Bob but it does not; the list's items are set to empty as soon as I enter text that is not contained in any of the items in the listbox!
Am I missing something here?
I dont see you cannot eliminate the if condition check and just have
CollectionViewSource.GetDefaultView(list.Items).Filter =
new Predicate<object>((item) => {
string valtoCheck = item.ToString();
return valtoCheck.StartsWith(filterText,
StringComparison.CurrentCultureIgnoreCase);
});
It's hard to tell without seeing more of the surrounding code but issues like this are usually related to Refresh not being called at the right times. It also looks like you may be reassigning the Filter over and over instead of setting it once and refreshing when the filter text changes.
Hi I am having an incredibly hard time with what should be a simple issue.
As of CodeIgniter 1.7, '$this->input->post();' supported arrays but I cannot for get the values into the array for some reason. I have 7 check boxes that store into an array 'services[]' as you can see by this example view:
<?php $servicesdata = array (
'name' => 'services[]',
'value' => 'in_home_care',
);
echo form_checkbox($servicesdata, set_checkbox('services[]', 'in_home_care', FALSE)); ?>
I'm quite certain this is the correct fashion because the forms do validate nicely if something goes wrong. Now I start to have issues when storing the values. I have 7 columns that need to have some sort of value... at this point I don't care but ideally it would be a boolean (a binary would work okay too). Here is what I have so far in my controller that everyone claims should work but just does not:
$c = new Client($servicesdata);
$c->first_name = $this->input->post('first_name', TRUE);
$c->in_home_care = $this->input->post('services[in_home_care]');
You can see the string I put for an example that works perfectly and inserts into a VARCHAR type while the array won't go into the database whatsoever. I feel as if that I am missing something here - namely the 'value' in the array but I'm just not sure where to go from here. Any help would be much appreciated because the only method I can get to work sacrifices my checkbox validation! :(
If your checkbox is unchecked, the value of the checkbox will not be entered into the $_POST array. This is probably where you are having problems.
There are two ways around this. Either have one box checked by default, or use HTML like the following (which may or may not be best practice/valid, but has worked for me in the past).
<input type="hidden" name="services" value="foo" />
<input type="checkbox" name="services" value="in_home_care" />
In the event that the box is not checked, the value "foo" for the name value "services" will be passed to the $_POST array.
First of all, there is some redundancy in your form (I think). You can set the attributes of your checkbox in the array, including whether it is checked or not:
$servicesdata = array (
'name' => 'services[]',
'value' => 'in_home_care',
'checked' => FALSE,
);
echo form_checkbox($servicesdata);
secondly, because you're naming it in an array, the object needs to be accessed after being assigned to another variable:
$checkbox_array = $this->input->post('services');
$service_type=$checkbox_array[0];//will give you 'in_home_care', [1] would be next in array and so on
A way to store those choices in the db is to create a string out of them and store that.
$this->input->post('colors') ? $colors=implode('-',$this->input->post('colors')) : $colors='';
That checks to see if anything was actually checked in the colors array. If so, create a string out of the array values seperated by dashes. Else assign empty to colors.
Then after you read the db string back:
$profile_data['colors']=explode('-',$row->colors);
Then you can feed those values back into the form inputs.