checking the selected item in select1 inside a repeat group - odk

I've a repeat group that starts with a select1 prompt, other questions that follow in the group is based on the item selected from the select1 (relevants). Every item in the select1 is mandatory and should be asked only once. How can I validate that an item is not selected again. Is there a mechanism to somehow avoid selection of already selected item. I've defined the select1 as
<select1 appearance="minimal" ref="/data/ITEMLIST">
<label ref="jr:itext('/data/listlabel:label')"/>
<item>
<label>मसिनो चामल</label>
<value>FRICE</value>
</item>
<item>
<label>खस्रो चामल</label>
<value>CRICE</value>
</item>
'
'
'

You can either:
a) validate using a constraint, e.g.
constraint="not(selected(/path/to/previous/question, .))"
b) use an XPath predicate that excludes previously selected values from the option list presented to the user, see e.g. this form (upload it to http://opendatakit.org/xiframe/, to get the XForm).
c) Just a thought, haven't tested, might be wrong: Maybe count all the other answers with the current value and add a constraint to make sure this is not more than 1. E.g.
constraint="count(/path/to/repeated[question = current()/.]) <= 1"
Note that there is currently a predicate bug in JR/ODK, so best to test if this works in Enketo. They're working on fixing the bug in JR.

Related

Oracle Apex checkbox

I have a page within my app with a Checkbox option.
The idea is basically to allow the user to select/unselect it if the change needs to be applied for every Sales Rep.
Something like this:
If checkbox is clicked = Change would be applied to all territories owned by the Rep
If checkbox is not clicked = Change would only be applied to the selected territory
I can't seem to get the checkbox clicked option to work.
I'm using an instr function to get a value out of it but it doesn't work:
select instr(':' ||:P11_CHECK_FOR_ALL|| ':', 'Request') into v_number_terr from dual;
if v_number_terr >0
(P11_CHECK_FOR_ALL is my checkbox Item / 'Request' is a word that's part of its label)
my checkbox pic
I'm trying to capture (in a process) whether the option is checked or not.
Could someone give me a hand please?
Thanks!
In apex a checkbox behaves just like a select list (with multiple selects possible). There is a display value and a return value. If nothing is selected, the page item value will be null. If one or more value are selected, the page item will contain a colon separated list of selected return values.
To handle the select list in a page process, the easiest is to split up the colon separated list in individual values using APEX_STRING.SPLIT
Example (untested):
DECLARE
l_check_for_all apex_t_varchar2;
BEGIN
l_check_for_all := apex_string.split(:P11_CHECK_FOR_ALL,':');
-- loop through the values. If nothing is selected then the COUNT will be 0 and nothing will be executed.
FOR i IN 1 .. l_check_for_all.COUNT LOOP
// do your pl/sql magic. You can reference the current item with l_check_for_all(i)
END LOOP;
END;

getting the selected item in select1 outside a repeat group

I am having some trouble implementing the relevants. I am suffering with getting the value of the selected item from my multiple select (the multiple select is outside the repeat group, the repeat group is where the implementation of relevant needs to be done).
I started off with a multiple select question ITEMLIST (readonly, all selected) outside a repeat group.
That limited my repeat loop (as intended) with the count of the selected items in the list (count-selected(/data/ITEMLIST))
I need to use the selected value of the first item(outside the repeat group) in the first repeat loop and so forth for all other iterations (managed to get the position - selected-at(/data/ITEMLIST, position(..)-1) and label - jr:choice(....) of the items in each iteration)
questions inside the repeat loop have relevants that if the item selected in the ITEMLIST is 1 then it needs to be shown else skipped, sth like.
I did some searches but could not implement anything.

Angularjs: default value when current option not in domain of select

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!

reorder array-table row and update database

I've been looking for a way to do something and I'm convinced I've been using the wrong search criteria to finding a solution...so, here I am.
I have a dropdown menu in a content management system that when a new page is created or position is edited, the database is updated with the new or edited value...this is all working great.
However, what I'd like to do is...when a number for the page position is changed from let's say, position 5 to position 1...the former position number 1 is changed to position number 2...and every position number for any pages remaining are renumbered accordingly.
So, my question is, how do I UPDATE my database so, whenever I change the position of the page in the dropdown menu, ALL position values get, I don't know, a +1...or something...and additionally, NOT allowing two position values to be the same...you know, there can be only one...
Thanks in advance...hope I didn't do too bad in explaining what I'd like to do :-)
Have you tried something like:
UPDATE my_table SET position=position+1 WHERE position>2 AND position<5
The where statement should be the new position & old position of the one you've just updated

better cucumber (Capybara-based) selection when multiple similar fields appear in a form

(Some background if it helps: our Rails app has a bunch of potentially repetitive dynamically-generated forms using double-nested fields, with ids in the pattern foo_attributes_0_bar_attributes_0_bat_12, where basically the first two numbers increment based on how many repetitions of the nested form there are, and the last number is the id of the particular "bat" object. This makes selection in Cucumber for testing difficult!)
I am trying to write some steps like this:
When I check the 1st checkbox with the value "Bat 12"
or
When I check the 3rd checkbox with id matching "bar_attributes_bat"
I have the following working, but my method of finding the checkboxes (or fields) seems pretty crappy and inefficient to me:
When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |number, junk, value|
check(page.all("input").select {|el| el.node['value'] == value}[(number.to_i-1)].node['id'])
end
When /^I check the (\d+)(st|nd|rd|th) checkbox with id matching "([^"]*)"$/ do |number, junk, id_string|
check(page.all("input").select {|el| el.node['id'] && el.node['id'].match(/#{id_string}/)}[(number.to_i-1)].node['id'])
end
Is there a better way to select these input elements?
When /^I check the (\d+)(st|nd|rd|th) checkbox with the value "([^"]*)"$/ do |index, junk, value|
page.all("input[value='#{value}']")[index.to_i-1].check
end
you can make use of xpath to click(check) the checkbox.here i use the same which had two input field,first one is hidden and second one is visible.here i click the second.
my html for checkbox taken from firefox.
<input type="hidden" value="0" name="approve[enabled]"/>
<input id="3" class="approveClass" type="checkbox" value="1" name="approve[enabled]"/>
//*[#id='MyList']/tbody/tr[2]/td[3]/input[2]
my checkbox is on the third column with no label in a table.for example
name type approve
rocky permanent [](checkbox)
#step in my scenario...
And I press xpath link "//*[#id='userList']/tbody/tr[2]/td[3]/input[2]"
#web_step.rb......
When /^I press xpath link "([^"]*)"$/ do |xpath|
page.find(:xpath, xpath).click
end

Resources