I am currently using oracle APEX 4.1 and have an issue with creating radiogroups dynamically.
I have a simple requirement(!) to display a list of questions from a table and display a yes/No radiogroup button next to each question. The list of questions may vary, so is not static.
To do this, I decided to create a plsql anonymous block and a sample of the code is below:
For c1 IN (select * from question)
LOOP
v_row:=v_row+1;
v_rowName:='F'||v_row;
v_radioYes:='<input type="radio" name='||v_rowName||' value="yes" />Yes';
v_radioNo:='<input type="radio" name='||v_rowName||' value="no" />No';
v_radio:=v_radioYes||' '||v_radioNo;
htp.p('<tr><td>'||v_row||'. '||c1.Question_text||'</td><td>'||v_type||'</tr>');
END LOOP;
So the questions are being displayed and the radiogroups are also being displayed next to each question.
My issue is that on submit, I need to find out what options a user has selected for each question and save to a database. Easy, but I cannot reference the radiobuttons for each question to find out what a user has checked.
Ideally, these radio button should have been created using the APEX tool, but I could not get this to do in a loop dynamically. Is there a way of referencing these radiogroups that have been created dynamically? Am I taking the wrong approach?
I have encountered almost the same problem recently. My solution to find the selected option was to add p_onchange parameter to APEX_ITEM.RADIOGROUP function invocation (refer to Apex 4.1 API Refernce). You can place any javascript code there. I have written a simple function to assign selected value to a hidden input field.
Here is the js function:
function put_selected_value(sel_value) {
$x('P66_SELECTED_VALUE').value=sel_value;
}
and RADIOGROUP
apex_item.RADIOGROUP(10, wrk_id, null, null, null, null,
'javascript:put_selected_value(this.value);')
Pfew. At first i thought this'd be a bit easier, but after mucking around a while i found radiogroups to be quite the toothgrinder. (this is on apex 4.1 btw)
Normally i'd respond that using apex_item would be the way to go to dynamically create items. However, radiogroups react with a twist.
If you'd use for example:
for r in(select level l, 'question '||level q, 'Y' a
from dual
connect by level < 6)
loop
htp.p('<div>'||r.q);
htp.p(
APEX_ITEM.TEXT(
p_idx => 1,
p_value => r.a,
p_size => 3,
p_maxlength => 1)
);
htp.p('</div>');
end loop;
The output would be:
<div>question 1
<input type="text" name="f01" size="3" maxlength="1" value="Y" />
</div>
<div>question 2
<input type="text" name="f01" size="3" maxlength="1" value="Y" />
</div>
<div>question 3
<input type="text" name="f01" size="3" maxlength="1" value="Y" />
</div>
<div>question 4
<input type="text" name="f01" size="3" maxlength="1" value="Y" />
</div>
<div>question 5
<input type="text" name="f01" size="3" maxlength="1" value="Y" />
</div>
Great! 5 fields generated, accessible by using apex_application.g_F01 array, where field 1 would be apex_application.g_f01(1).
Radiogroups however react differenty. What APEX_ITEM.RADIOGROUP does is not actually creating a radiogroup, but creating a radiobutton. The group would then be the f01 array.
Woah! I don't like that! The F## arrays only go from 1 to 50 to start with, so if you'd generate a few items, this is not ideal.
Also, your logic gets screwed: suddenly you don't have to loop over an array anymore, but over arrays.
For example, the output would be like this if you'd replace apex_item.text with apex_item.radiogroup
<div>question 1
<input type="radio" name="f01" value="Y" />Yes?
</div>
<div>question 2
<input type="radio" name="f01" value="Y" />Yes?
</div>
<div>question 3
<input type="radio" name="f01" value="Y" />Yes?
</div>
<div>question 4
<input type="radio" name="f01" value="Y" />Yes?
</div>
<div>question 5
<input
It sort of did what you asked: it created a radiogroup consisting of the items. If you'd click the button at question 4 and question 1 was previously marked, the mark will be removed from question 1 and set to 4.
It works however. When you submit and loop over the F01 array, it'll pass the value along:
--this after submit process
for i in 1..apex_application.g_f01.count
loop
apex_debug_message.log_message('array F01: item '||i||': '||apex_application.g_f01(i));
end loop;
--results in this debug message:
--array F01: item 1: Y
Okay, so what are your options then? Don't use this. It is not dynamic! You can't loop over the 50 arrays, unless you write 50 loops over each array...
So how does APEX actually work then? When looking at the output code of a page item radiogroup, this is the output:
<input type="hidden" name="p_arg_names" value="50795996117686343389" />
<fieldset id="P3_RGROUP_PAGE_ITEM" tabindex="-1" class="radio_group">
<input type="radio" id="P3_RGROUP_PAGE_ITEM_0" name="p_t01" value="Yes" checked="checked" />
<label for="P3_RGROUP_PAGE_ITEM_0">Y</label><br />
<input type="radio" id="P3_RGROUP_PAGE_ITEM_1" name="p_t01" value="No" />
<label for="P3_RGROUP_PAGE_ITEM_1">N</label></fieldset>
See the hidden item? I assume apex puts the selected value in that hidden item, so you can easily reference the chosen value of the radiogroup.
This is probably the best way you can solve this. Generate your radiogroups and buttons and put the selected value in a hidden item using javascript. You can create the hidden item using apex_item.hidden, which you can thankfully refer to easily in an array afterwards. If you'd use p_idx => 1, all hidden items will be stored to array g_f01.
You'll just need to piggyback this hidden item in your radiogroup container. Then bind an onchange event to your radiobuttons.
Example, look at this jsfiddle. This'll keep the selected value in the hidden item, which will be posted on submit.
Sorry for the lenghty post, i didn't think it'd get so complicated. Hopefully someone comes along and shows us an easy way :)
Related
I am a begginer in jQuery could you help me build a script for this?
I have set's of fieldset which have set of input
<p><input type="radio" class="scenarioRadio" value="5" name="group26" /><label>Strongly agree </label></p>
<p><input type="radio" class="scenarioRadio" value="4" name="group26" /><label>Somewhat agree </label></p>
<p><input type="radio" class="scenarioRadio" value="3" name="group26" /><label>Neither agree or disagree</label></p>
<p><input type="radio" class="scenarioRadio" value="2" name="group26" /><label>Somewhat disagree</label></p>
<p><input type="radio" class="scenarioRadio" value="1" name="group26" /><label>Strongly disagree </label></p>
<p><input type="radio" class="scenarioRadio" value="0" name="group26" /><label>Don’t know / Can’t say</label>
Now I have set of conditions:
If two responses have equal numbers and they are next to each other, display the lower value response.
Ex.
1st user answer: Strongly agree [value="5"]
2nd user answer: Somewhat agree [value="4"]
Final answer should be the lower rank: Somewhat agree [value="4"]
If two responses have equal numbers but are not next to each other, display "Don't know / Can't say"
Ex.
4 say they “Strongly disagree”
while 4 say they “Somewhat agree” (which is what I mean by "equal numbers")
Then the result is the lowest “Don’t know / Can’t say” [value="0"]
What should I use for this kind of conditions? and how to build it?
Thanks in advance!
Hi,
I'm creating dynamic input textboxes starting with name: loan0 and also name: balance0
I would like to have classic asp put the values into two arrays
HTML:
<input type="text" name="name" value="John">
<input type="text" name="phone" value="1234567">
<input type="text" name="loan0" value="bla">
<input type="text" name="loan1" value="blabla">
<input type="text" name="balance0" value="test1">
<input type="text" name="balance1" value="test2">
...........and so on...............
Classic ASP:
loan_array = bla,blabla ... and so on..
balance_array = test1,test2 ... and so on...
What I tried:
dim loan_array
loan_array = ""
For Each item In Request.Form
loan_array = loan_array & Request.Form(item) & ","
Next
Response.write loan_array
end if
PROBLEM: The result I get back is all of the values in all of the input textboxes, but I only want those that start with the name balance followed by a number (starting with 0) and loan followed by a number (starting with 0)
THANKS SO MUCH FOR ANY HELP.
Why do this when ASP can do it for you?
HTML:
<input type="text" name="name" value="John">
<input type="text" name="phone" value="1234567">
<input type="text" name="loan" value="bla">
<input type="text" name="loan" value="blabla">
<input type="text" name="balance" value="test1">
<input type="text" name="balance" value="test2">
<!-- ...........and so on............... -->
Classic ASP:
Response.Write Request.Form("loan")
Output:
bla, blabla
ASP will even build the delimited string based on the order of the form elements with the same name occur.
Update:
Based on feedback about handling commas inside the request, I've done a bit of testing myself and the issue is due to how Request.Form("loan") automatically decodes and collates the entries together but there is a simple way around this and that is to iterate through the instances of Request.Form("loan") rather then just calling Request.Form("loan") and having them automatically collated together.
HTML:
<input type="text" name="loan" value="bla">
<input type="text" name="loan" value="blabla">
<input type="text" name="loan" value="test1,test2">
<input type="text" name="loan" value="test3">
<!-- ...........and so on............... -->
Classic ASP:
Dim item
For Each item In Request.Form("loan")
Response.Write item & "<br />"
Next
Output:
bla
blabla
test1,test2
test3
The way you should do it is what Lankymart wrote, i.e. using the same name for all the related fields, and letting ASP do the concatenating-to-string for you. (And then if you want it as an array, you can just do a Split() on the commas.) However, if you really want to do it yourself, you can concatenate field names in Request.Form:
N = Request.Form("N") '- number of fields per type
redim loan_array(N) : redim balance_array(N)
For i = 0 to N
loan_array(i) = Request.Form("loan" & i)
'- might as well take advantage of this one-at-a-time approach:
If Not IsNumeric(loan_array(i)) Then
loan_array(i) = 0
Else
loan_array(i) = CLng(loan_array(i))
End If
balance_array(i) = Request.Form("balance" & i)
'- etc.
Next
'- one reason for doing it this way might be that your data has commas in it:
Const delimiter = ";"
loan_list = Join(loan_array,delimiter)
balance_list = Join(balance_array,delimiter)
This counts on there being a known number of fields of each type, but I can't imagine a scenario where you don't know that - if nowhere else, right after generating/writing out your form:
<input type="text" name="loan0" value="<%=loan_array(0)%>">
<input type="text" name="loan1" value="<%=loan_array(1)%>">
<input type="text" name="loan2" value="<%=loan_array(2)%>">
...
<input type="hidden" name="N" value="2">
Perhaps this will help.
dim loan_array, myCounter
loan_array = ""
myCounter = 0
For Each item In Request.Form
loan_array = loan_array & Request.Form(item) & myCounter & ", "
myCounter = myCounter+1
Next
Response.write loan_array
I'm trying to parse an existing document and modify it by wrapping a div around some existing form elements.
HTML form looks a bit like this:
<form>
<label for="username">Username:</label>
<input name="username" type="text" />
<label for="password">Password:</label>
<input name="password" type="password" />
</form>
I can parse the document OK with Nokogiri and i'm aware of the wrap method but i'm struggling to grasp how to select both the label and input tags in one go and then wrap a div around these. So the result I am looking for is:
<form>
<div class="form-group">
<label for="username">Username:</label>
<input name="username" type="text" />
</div>
<div class="form-group">
<label for="password">Password:</label>
<input name="password" type="password" />
</div>
</form>
I have tried various XPaths / CSS selectors and can create a nodeset of just labels/inputs or all of the elements of the whole form. Is there any way to achieve this modification?
A single XPath expression can only return a single collection of nodes, so in order to achieve what you want you will need to make several queries, one for each label – input pair.
You can select an individual pair with something like this, assuming the markup is well behaved (i.e each input has a label before it):
//label[1] | //label[1]/following-sibling::input[1]
This will select the first label and the following input. However you want to select all such pairs. One way would be to first select all the label nodes, and then for each label select it and the following input.
labels = doc.xpath("//form/label")
labels.each do |l|
nodes = l.xpath(". | ./following-sibling::input[1]")
# nodes now contains a label-input pair...
end
I don’t think the wrap method will work to add a div element as an ancestor to each pair, as it will add the element to each member of the nodeset. You will probably have to move them manually, something like
labels = doc.xpath("//form/label")
labels.each do |l|
# Select this node and its neighbour.
nodes = l.xpath(". | ./following-sibling::input[1]")
# Create the new element, and add it before the label.
div = Nokogiri::XML::Node.new('div', l.document)
l.before(div)
# Move each of the pair onto this new element.
nodes.each do |n|
div.add_child(n)
end
end
Note that this method doesn’t move any text nodes, so you may find the whitespace of your document changes a bit.
I have used pattern I want to price equal 30 or Greater BUT not less.
Look my html code -
<input type="text" required="required" pattern="29+\.[0-9]*[1-9][0-9]*$" data-error="#Please enter price equal 30 or more" placeholder="Price" id="price" class="form-control" autocomplete="off" name="price" />
<div class="help-block with-errors"></div>
Above co I have used pattern="29+\.[0-9]*[1-9][0-9]*$" but this pattern not working. I have tried in different expression like 29*\.[0-9]*[1-9][0-9]*$, ^\d{30,}$, ^[0-9]\{30,}\$ these expressions also not working.
I am using bootstrap validator. Link = http://1000hz.github.io/bootstrap-validator/#validator-examples
Please help me.
*Edit : *
Now I am using ^[3-9]+\d*$ this is working fine. But it takes 3 or more than 3. I need 30 or more
You really should not be using regexes for this kind of task. But if you do want to, try this:
([3-9][0-9]|[0-9]{3,})
I would like to select a checkbox from an excel spreadsheet for a data driven test.
code for the checkbox:
Not Checked:
<input type="checkbox" class="greenopt" name="Accounts[0][greenopt]" id="" value="0">
Checked:
<input type="checkbox" class="greenopt" name="Accounts[0][greenopt]" id="" value="1">
I tried the following but get the error: Unable to locate element, using {:value=>"1"}
greenopt_check=worksheet.cells(rows,"O").value
browser.checkbox(:value => greenopt_check).set
this is kind of similar to my previous question regarding radio buttons
Select Radio buttons from excel with ruby
Please review the watir checkbox documentation. in that case you can checkbox.set or checkbox.clear depending on your goals.
You want to use something that is unique, and consistent/predictable to select elements
checkbox_class = worksheet.cells(rows,"A").value
puts 'retrieved checkbox_class from spreadsheet is:' + checkbox_class #for debugging, make sure you got the correct thing from the spreadsheet
browser.checkbox(:class => checkbox_class).set
or
checkbox_name = worksheet.cells(rows,"A").value
puts 'retrieved checkbox_name from spreadsheet is:' + checkbox_name #for debugging, make sure you got the correct thing from the spreadsheet
browser.checkbox(:name => checkbox_name).set