Conditionally capturing pre-determined text in one field based on multiple choice selection in another field in REDCap - conditional-statements

Problem: How can you capture a pre-determined or static text value based on what choice a user makes from a multiple choice menu on a survey?
Example: Suppose you have the following basic setup:
I have four text statements that correspond to options 1-4 (e.g., "Statement corresponding to Option 1", "Statement corresponding to Option 2", etc.). If the user chooses, say, Option 1 from the sample_options field, then I would like to capture the text value of the pre-prepared statement in the option_statement field. The user should not be able to alter the captured text statement (e.g., maybe hide the field using the #HIDDEN action tag).
Attempt: It seemed like this might be a problem that could be resolved with action tags, namely the #DEFAULT one, but I have been unable to do this. I also thought about trying to use a calculated field instead of a text field for option_statement, but calculated fields must return numeric values:
This seems like a problem that should be somewhat straightforward to tackle, but I have been baffled by just how hard it seems to be to simply capture static text in one field based on a user's selection in another field.

If I understand the question, you want to select a text string from a list of (in this case) 4 options, depending on the user selecting a choice from a radio/dropdown?
Probably the easiest method is to use #CALCTEXT (if you are on a sufficiently recent version), which allows you to conditionally populate a text field, i.e.:
#CALCTEXT(
if([sample_options] = 1, "This is the label for option 1",
if([sample_options] = 2, "This is the label for option 2",
if([sample_options] = 3, "This is the label for option 3",
if([sample_options] = 4, "This is the label for option 4", "This is an else value")
)
)
)
)
But if you do not have #CALCTEXT available to you, you can do this with a #DEFAULT, by constructing another radio field (#HIDDEN if you like) on a separate page or instrument (as #DEFAULT needs the value to exist in the database on page load, and so does not work dynamically on the page), with your four labels as the options with the same choice codes as your [sample_choices] field. For example:
1,This is the label for option 1
2,This is the label for option 2
3,This is the label for option 3
4,This is the label for option 4
And annotate it with:
#DEFAULT='[sample_choice]'
Thus if a user selects 3 for [sample_choice] and proceeds to the page or instrument that has the label field, the #DEFAULT tag will automatically select choice 3 from the label field, which can then be stored in the dataset and piped into an email, onto the page, or whatever.

Related

Store as Json Blob or Make Columns?

I am building a "filter component" that displays all available filters for that "product type".
Pretty standard pretty much just think of bestbuy, amazon, craiglist style filter.
Right now I am focusing on how to generate the filter options(not how to handle once a user clicks on a filter option and it must then go off and filter the results down).
So I created a json object that has something like this,
which will create each header section(HardDrive,Ram Size, Number of CPU Cores), what type is it(checkboxes, textboxes),
should the section be opened,
should it have a search box in it.
{
type: "", // this is what type of filter it will be (textbox, checkboxes and etc)
header: "Filter Header",
property: "", // this maps it back to the column name in db used when filter is actually triggered.
hasSearchBox: false, // some filter options are long so search box can be shown.
isOpen: true, // controls if this filter should be in an open or closed state.
for: ["What Products this filter applies to. Some of these filters are common between all products"]
},
Now I need to figure out if I should store the above as is or if I should break it into a column format.
Ie
Filters Tbl
Id
ProductTypeId
type
header
property
hasSearchBox
isOpen
This does make it easier to add a new filter in the future, but I am bit concerned if some new option comes in that might only be for some filters and not others(ie lots of null columns) or if I need a more complex objects in the future(like setting the placeholder name for the textbox).
or if I should store it like this
ProductTypeTable
Id
FilterOptions <--- json from above gets store in here.

How to Select Choices input field having same class, type, Xpath everything is same

I have two input fields to enter choices which have same class, type. Id is different by it is dynamic and create on run time so i can't use id.I used indexing ,it's not working properly.
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).sendKeys("Iphone 6");
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).sendKeys("Iphone 7");
I used indexing in given image link.
click link to view code in organized way
Index 1 works in this case but unable to find index 2.
Given inspected html code is below of input field 1 and field 2
Field 1
Input field 1 image Xpath link
field 2
Input field 2 image link
If these two inputs are always in this sequence (so the first input is always first and second always second)
You can use:
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[1]")).click();
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[2]")).click();
At the same time I have corrected the syntax in indexing
Building on #Anand 's answer, you can simplify a little:
WebElement button1 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[1]"));
WebElement button2 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[2]"));
I think it's a little easier to read using and instead of stacking brackets.
I use it similarly for widgets:
WebElement header = driver.findElement(By.xpath("//div[contains(#class,'panel')]/div[contains(#class,'panel-heading') and text()[contains(.,'News Feed')]]"));

The method getKids() is undefined for the type PDField

https://issues.apache.org/jira/browse/PDFBOX-2148
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null. So if the parent field is called Button2 and it has 4 instances the result of printing out all the names will be:
Button2.null
Button2.null
Button2.null
Button2.null
According to the comments to the question, the OP refers to PDFBox 2.0.x versions, in particular 2.0.6.
getKids()
The method getKids() is undefined for the type PDField
In PDFBox 2.0.6 there are two immediate sub-classes of PDField. Different variants of the former (1.8.x) getKids() method are implemented in there:
PDNonTerminalField - the method retrieving the kids in this class is getChildren() and returns a List<PDField>, a list of form fields.
PDTerminalField - the method retrieving the kids in this class is getWidgets and returns a List<PDAnnotationWidget>, a list of widget annotations.
name of the parent, followed by .null
When there are multiple copies with the same field name, the getFullyQualifiedName for each kid in the list of PDField objects returns the name of the parent, followed by .null
This is not the case in PDFBox 2.0.x.
In the sample document attached to the PDFBox issue PDFBOX-2148 PDFBox now correctly finds only a single field which appropriately is named "Button2". This field is a PDTerminalField and has 4 widget annotations. The class of the latter, PDAnnotationWidget, has no getFullyQualifiedName method, so there are no ".null" names.
Thus, this problem is gone.
FQN of duplicate fields
(from the OP's comment responding to "What exactly is your question?")
how to get Fully Qualified Name of duplicate fields in pdfbox
There are no duplicate fields in (valid) PDFs, for a given name there is at most a single field which may have multiple widgets. Widgets do not have individual FQNs.
Thus, what you call "duplicate fields" in your example document actually is a single field with multiple widgets; the name of that field is "Button2" and can be retrieved using getFullyQualifiedName().
which page which form field
(from the OP's comments to this answer)
but how to get current page no in pdfbox.. for example there are 3 page and in page 2 there is a form field so how can i get which page which form field ?
All PDAnnotation classes, among them PDAnnotationWidget, have a getPage() method returning a PDPage instance.
BUT: As specified in ISO 32000-1, annotations (in particular form field widgets) are not required to have a link to the page on which they are drawn (except for screen annotations associated with rendition actions).
Thus, the above mentioned method getPage() may return null (probably more often than not).
So to determine the respective pages of your widgets, you have to approach the problem the other way around: Iterate over all pages and look for the annotation widgets in the respective annotation array.
For PDFBox 1.8.x you can find example code in this stackoverflow answer. With the information given in the previous parts of this answer it should be easy to port the code to PDFBox 2.0.x.
checkbox and radio button
(also from the OP's comments to this answer)
one more issue if i am using checkbox and radio button both then field.getFieldType() output is Btn for both. how to identify it?
You can identify them by inspecting the field flags which you retrieve via fields.getFieldFlags():
If the Pushbutton flag is set (PDButton.FLAG_PUSHBUTTON), the field is a regular push button.
Otherwise, if the Radio flag is set (FLAG_RADIO), the field is a radio button.
Otherwise, the field is a check box.
Alternatively you can check the class of the field object which for Btn may be PDPushButton, PDRadioButton, or PDCheckBox.
Beware: If a check box field has multiple widgets with differently named on states, this check box field and its widgets act like a radio button group! And not only in theory, I've seen PDFs with such check box fields in the wild.
To really be sure concerning the behavior of the fields, you therefore also should compare the names of the on states of all the widgets of a given check box.

Does mvc 4 application need another model to return aggregate data on an existing table and model

I have a table (and model) with the following properties in an asp.net MVC 4 application:
TV Table
height
width
depth
type
brand
cost
When the user answes a question about the space that they have for the TV I then do an ajax call to determine which types are possible to fit into the space they have specified. Which type of TV type they want is the following question, so some options may need to be disabled. The SQL for what types fit in the space is "select distinct type from TV where height < #height and width < #width and depth < #depth".
Should I:
1. create a new model that I call from the TV controller just to return the distinct types
2. add a method to the TV model that I call from the TV controller that just returns a list of string with the types that fit
Depends on what you want to display to the user based on her selection' e. g.
If you want to display TV name + its description then returning a list of TV model will make sense.
If you are just going to display a list of TV names in combo box, then returning a list of string will suffice.
Calling a new action make sense in both cases IMHO.
EDIT:
For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string?
To expand on above query, since its not clear (at least I do not visualize it) from your question i will assume few things.
Case 1: You are displaying a view say "TVSelection" to the user that does not contain list of TVModels. In this view you are expecting user to enter three values i.e. Width, Height, Depth. Now when user enter these values, she can submit the form or you can fetch the TV Brand name list on Lost Focus event as well. In any case, the question would be are you updating existing view by populating the combo box or you are displaying a new view. I am assuming you are updating existing "TVSelection" view by the means of making an AJAX call. In that case you can just call a method on your controller (which displayed the "TVSelection" view) that returns a list of TV Brand names.
Case 2: You are displaying "TVSelection" view that already has a list of TVModel objects and you update it dynamically on selection of required field (filtering). In this case you can add a method in the TVModel itself to filter names only that matches the user selection.
I found these links relevant 1 & 2.
Hope that make sense.
Please add more details to your question if this does not answer your question.

Fixed text when scrolling

My program displays an ABAP list, I'm trying to show a header (some lines of text, nothing fancy) fixed when scrolling down in a report.
Is there some kind of tag or declaration that I have to use?
In SE38 you can define list heading with 'GOTO -> Text Elements -> List Headings`.
You can define a list header, and titles for your list (Columns heading).
One advantage: With GOTO -> Translations you can define different texts in different languages.
Another way to get this maintenance screen:
From your list, you can choose: System -> List -> List Header.
Another way:
You can use top-of-page to define your header text inside your report code.
top-of-page.
write 'My header'.
You can use the TOP OF PAGE event to write something that will stick at the top of the page while scrolling. You can find more info here.
You can also use the list headers from Text Elements menu. More info here.
Best regards,
Sergiu
One way is directly using top-of-page in your code.
Other way is calling reuse_alv_grid_display or reuse_alv_list_display (depending on your output type) and declaring "top-of-page" in the I_CALLBACK_TOP_OF_PAGE line. Then create a sub-routine with the same name as your "top-of-page". In that you can write
wa_list-typ = 'H'.
wa_list-info = ''.
APPEND wa_list to it_list.
clear wa_list.
OR
wa_list-typ = 'A'.
wa_list-info = 'Report Header'.
APPEND wa_list to it_list.
clear wa_list.
OR
wa_list-typ = 'S'.
wa_list-info = 'Report Header'.
APPEND wa_list to it_list.
clear wa_list.
depending on what you want (header, action or selection).
Finally you can use REUSE_ALV_COMMENTARY_WRITE function and call the table(in this example it_list).
Hope it helped.