Variable number of fields in form using struts 1.X - struts

I need to build a form that loads a table that in each row contains a checkbox and an input text (the number of rows is variable, because it's loaded from a db). So my questions are:
What fields should the associate formbean have ? ArrayLists ? One HashMap ?
How can I know (once the form is submitted) what checkbox was selected so I consider the corresponding input text ?
I'm using struts 1.X as framework.
Thanks in advance!

Personally, I would use an array (list) for the checkboxes and a map for the input texts. You have to consider the fact that checkboxes are not sent on the request if they are not selected, but all your input texts are always sent. So, match the value of a checkbox with the map parameter of an input text, something like:
<input type="checkbox" name="ckName" value="val1" ../>
<input type="text" name="mapMethod(val1)" ../>
<input type="checkbox" name="ckName" value="val2" ../>
<input type="text" name="mapMethod(val2)" ../>
<input type="checkbox" name="ckName" value="val3" ../>
<input type="text" name="mapMethod(val3)" ../>
...
This means you will always have a map with all values:
val1 = "textbox 1 value"
val2 = "textbox 2 value"
val3 = "textbox 3 value"
...
and also have a list of selected checkboxes which can be:
[val1]
[val1, val2]
[val1, val2, val3]
... different combinations or []
You then keep the textbox values from the map only for the keys that are found in your list of checkbox values.
P.S. Remember also to reset your checkboxes.

Related

How to enter a different text in same element after clicking in Add button?

Application has ADD Button, that need to be clicked after entering Fname and Lname. Once ADD button is clicked, another Fname and Lname text fields appears. I have tried to use index, but not worked. Text is getting entered in the first text box multiple times.
<input class="mat-input-element mat-form-field-autofill-control ng-touched ng-dirty ng-valid" matinput="" type="text" autocomplete="on" name="undefined" min="undefined" max="undefined" required="" maxlength="50" id="mat-input-16" placeholder="First Name" aria-invalid="false" aria-required="true">
First time the text is getting entered in the Element.
private IWebElement Input_Auto_SomeOneInjuredLname => FindElement(By.Id("mat-input-13"));
Input_Auto_SomeOneInjuredLname.SendKeys(data.Auto_IsSomeoneInjuredLname);
Find Element by XPath as follows:
(//input[#placeholder="Last Name"])[3]
(//input[#placeholder="First
Name"])[3]
Change needs to be done :
(//input[#placeholder="First Name"])[_ADD_INDEX_VARIABLE]
(//input[#placeholder="Last Name"])[_ADD_INDEX_VARIABLE]
Increment the value of Index Variable through for loop or while loop
starting with value =1

How to validate Check box if xpaths are same in case of selected and unselected

M unable to validate checkbox, if it's selected or not
because both the HTML are same
I tried isSelected(), but it's not working
Below is the HTML code for both selected and unselected
1) Selected
<label class="c-account-access-panel__checkbox " for="23336" data-js-checkbox-label="">
<input id="23336" class="c-account-access-panel__checkbox-input" type="checkbox"
data-label-for-value-missing="Please select at least one account from the options below" data-form-field-validation-on-grid=""
required="" checked="" data-js-checkbox="" value="DE29973399" name="payer"/>
<div class="c-account-access-panel__checkbox-symbol"/>
2) Unselected
<label class="c-account-access-panel__checkbox " for="23336" data-js-checkbox-label="">
<input id="23336" class="c-account-access-panel__checkbox-input" type="checkbox"
data-label-for-value-missing="Please select at least one account from the options below" data-form-field-validation-on-grid=""
required="" checked="" data-js-checkbox="" value="DE29973399" name="payer"/>
<div class="c-account-access-panel__checkbox-symbol"/>
Thanks in advance!
As per the Java Docs isSelected() method determines whether the element is selected or not. This operation only applies to <input> elements such as checkboxes, options within a <select> tag and radio buttons.
To validate if the desired checkbox is selected or not you can use the following code block:
boolean checkboxSelected = driver.findElement(By.xpath("//input[#class='c-account-access-panel__checkbox-input' and #name='payer']")).isSelected();
If isSelected() is not working for you. Then , you can use JavascriptExecutor to do your task. Following JS statements shall let you know the state of target checkbox.
document.getElementById("23336").click();
document.getElementById("23336").checked;
The checked method returns true or false depending on the checkbox state.
You can validate using getAttributemethod.
First select the webElement using any of the unique locator,
WebElement checkbox=driver.findElement(By.xpath(".//input[#type='checkbox']"));
If the checkbox is selected, then checkbox.getAttribute("checked")will give the result as true else, it will give the result as null. So, you can add the condition using checkbox.getAttribute("checked")
Use xpath expression like: (//div [#id='23336')[1] or (//div [#id='23336')[2] to make them into unique element then do .isselected ()

Vue - conditional attribute binding

I am making a form in a Vue component and would like to set the HTML attribute required to an input field based on the value I am having in an object property.
So, for the example, an object that has fields like this:
label:"Name"
required:"1"
type:"textbox"
I need to a set the field to have required attribute in an input tag:
<input class="input is-large" :type="input.type" required>
And for the ones that don't have 1 as a value for that field I don't want a required attribute.
How can I do that in Vue?
You can do it like this:
<input class="input is-large" :type="input.type" :required="obj.required == 1">
Since your object's required property has 1 as a string not number I used == for comparison so that equality is tested after coercion

TestStack.Seleno TickCheckbox not working

I have 2 forms that I am testing using TestStack.Seleno. Both forms have a checkbox that is mandatory. The first form has (including the checkbox) 5 fields. I can use TestStack.Seleno to create a passing test with valid data. I set the checkbox like this:
Input.TickCheckbox(f=>f.Accept,form.Accept);
On my other form which has 10 or so fields, when I try to set the checkbox to be ticked (using the same code) nothing happens. However when I try
var acceptCheckBox = Find.Element(By.Name("Accept"),new TimeSpan(0,0,0,50));
if (form.Accept)
{
acceptCheckBox.Click();
}
I get error "Element is not currently visible and so may not be interacted with"
Element is clearly visible and is not injected in using javascript.
I am using latest version of TestStack.Seleno from github.
Any ideas?
So I have managed to figure out what the issue is and have a work around, however I cannot explain why it works on the other form. The mandatory Accept field has html generated by mvc that looks like
<div>
<input class="check-box" data-val="true" data-val-mustbetrue="The Accept our field is required" data-val-required="The Accept our field is required." id="Accept" name="Accept" type="checkbox" value="true"><input name="Accept" type="hidden" value="false">
<label for="Accept">
Accept our Please accept our Terms and Conditions
</label>
<span class="field-validation-valid" data-valmsg-for="Accept" data-valmsg-replace="true"></span>
</div>
So you have the checkbox and hidden field both with id Accept, I suspect in code seleno is picking up the hidden field and setting value, so I updated my code todo
var acceptCheckBox = Find.Element(By.CssSelector("#Accept.check-box"));
acceptCheckBox.Click();
Now everything works.
Ismail

how to set name of multiple textbox in openerp using qweb template engine?

Here is my code:
<tr t-foreach="keyword" t-as="item"><td><t t-esc="item_value"/></td><td><input type="text" name=""/></td></tr>
So here, Textbox are generated dynamically.
Now I want to set textbox name to the value that is generated on
<t t-esc="item_value"/>
To set the text box name to item_value you need to use the t-att attribute:
<input type="text" t-att-name="item_value"/>
Hope this helps!