My checkbox should not repeat in an iterate loop - struts-1

I have a <logic:iterate></logic:iterate> loop in which I added a checkbox I want that the checkbox should not be added after every element in <iterate> loop.
I only want to print my:
<input type="checkbox" id="configureCheckBox" >Configure<br/>
this checkbox with only first element.

Assuming that you are using an s:iterator tag (since the question is tagged as struts2), you can use the status attribute to check if you are printing the first element:
<s:iterator value="yourVar" status="cycleStatus">
<s:if test="#cycleStatus.first">
<input type="checkbox" id="configureCheckBox" >Configure<br/>
</s:if>
<%-- other code --%>
</s:iterator>
See also the s:iterator and IteratorStatus documentation.

You can play with indexId in this case.
You can use something like
<logic:iterate indexId="index">
<%if (Integer.parseInt(String.valueOf(index))){%>
<input type="checkbox" id="configureCheckBox" >Configure<br/>
<%}%>
</logic:iterate>

Related

Conditional display within a merged block

I am trying to get conditional display to work properly. What I am attempting to do is:
Within a block that has been merged, if a value is empty I want to display an input box along with a few other hidden variables I need to carry along with it, but if the value is not empty I wish to simply display that value.
PHP
$cks . . some query;
$TBS->LoadTemplate("check.html") ;
$TBS->MergeBlock("cks",$cks);
$TBS->Show(TBS_NOTHING); echo($TBS->Source);
Template portion
<td width="25%" class="mod_row2">[cks.check1]</td>
<td width="25%" class="mod_row2">
[cks.value;ifempty=
<input type="text" name="value[]" value="" size="26">
<input type=hidden name="check_id[]" value="[cks.check_id]">
<input type=hidden name="equip_id[]" value="[cks.equip_id]">
]</td> "
Everything works except the values of the hidden cells are not merged. I don't know if this is the right way to do this or if this is possible . . .
TBS 3.8.0, php 5.3.3
Thanks
Peter
Your HTML part with <input> is not parsed because it is embedded in a TBS parameter (ifempty).
It is not a good practice to embed HTML/XML in the TBS fields.
The best way is to use conditional display with block. The magnet feature is nice for that.
Example for you :
<td width="25%" class="mod_row2">[cks.check1]</td>
<td width="25%" class="mod_row2">
<div>
[cks.value;ope=mok:;magnet=div]
<input type="text" name="value[]" value="" size="26">
<input type=hidden name="check_id[]" value="[cks.check_id]">
<input type=hidden name="equip_id[]" value="[cks.equip_id]">
</div>
</td>
In this example, the parameter ope=mok: means that the block is displayed if the value is empty string (''), and is deleted in other cases.

How do i match the value which has a radio button checked

I have a list of similar looking DIVs without any Div ID, except one has a check box checked and others doesn't. What i need is to find the value from a child tag only if a radio button is selected.
Below is a simpler version of my code.
<div class = "XYZ">
<input type="radio" checked>
<input type="hidden" value="This is a great thing 1">
</div>
<div class = "XYZ">
<input type="radio">
<input type="hidden" value="This is a great thing 2">
</div>
Result needed is
This is a great thing 1
Unfortunately the source code cannot be changed.
Your xpath should look for a div that contains the checked input and to get the value for the one that has value attribute.
First selector returns the input, the second returns the value.
//div[.//input[#checked]]/input[#value]
//div[.//input[#checked]]/input/#value
As an alternative you can use the following sibling:
//input[#checked]/following-sibling::input
If you want to also use the class of the parent div:
//div[#class='XYZ']/input[#checked]/following-sibling::input

how to assign value directly to kendo data-bind

how to assign value directly to kendo data-bind
here is the code
<script type="text/x-kendo-template" id="add-new-user-template">
<li>
<a class="user-result">
<span class="row-name">Create New User</span>
<br/>
<input type="hidden" class="hf-user-role-id" data-bind="value: 0"/>
<input type="hidden" class="row-party-id" data-bind="value: "/>
</a>
</li>
</script>
hav to set first input field value to 0 and second to empty string
Ok, I don't really know if I understood what you try to achieve, but if you want to set static values, why not just doing <input type="hidden" name="user-id" value="0" class="hf-user-role-id" /> since there is (in my opinion) no sense of binding static values.
The data-bind attribute needs a variable or some JSON to be bound to not a static value.
Cheers
If I understand correctly you want to do this:
$('.hf-user-role-id').attr('data-bind', "value: 0");
$('.row-party-id').attr('data-bind', "value:");
The jquery attribute method allows you to change the values of an attribute.
If you are using kendo ui then you will almost certainly have included jquery.

Form Submit using a Javascript to invoke webflow transition, doesn't take the updated value on form

I am trying to invoke a form submit using javascript (jquery) to invoke a webflow transition. It works and the submit invokes the desired transition. But, the updated radio button values is not reflected on the model object which is posted.
Here is the code:
<form:form method="post" action="#" commandName="infoModel" name="pageForm">
<form:input type="input" path="testMsg" id="success" />
<input type="button" id="clearSelections" value="Clear Selections">
<div class="question">
<h4><c:out value="${infoModel.questionInfo.description}"/> </h4>
<form:radiobuttons path="infoModel.answerId"
itemValue="answerId" itemLabel="answerDescription" items="${infoModel.answers}" delimiter="<br/>" />
</div>
<input type="submit" name="_eventId_saveQualitativeInput" value="Save" id="save" />
$(document).ready(function() {
$('#tabs').tabs();
//Clear selections (copy is server-side)
$('#clearSelections').click(function() {
//$('input[type="radio"]').prop('checked', false);
$('input[type="radio"]').removeAttr('checked');
$('#save').trigger('click');
});
});
</form:form>
The form:radiobutton, generates the below html:
<div class="question">
<h4>Is this a general obligation of the entity representing a full faith and credit pledge? </h4>
<span>
<input type="radio" checked="checked" value="273" name="infoModel.answerId" id="infoModel.answerId1">
<label for="infoModel.answerId1">Yes</label>
</span>
<span><br>
<input type="radio" value="274" name="infoModel.answerId" id="infoModel.answerId2">
<label for="infoModel.answerId2">No</label>
</span>
<br>
<span class="error"></span>
</div>
The input id= "success" value is registered and when the control goes to the server, the value of input id= "success" is updated in the "infoModel" object. But the value of answerId is not updated on the "infoModel" object.
Thoughts if i am missing something in the form:radiobutton element or if there is something else wrong?
Thanks in advance!
EDIT:::::::
Thanks mico! that makes sense. I stripped of some of the code first time to make it precise, but i have a list which is being used for building the radio-buttons, below is the code:
<c:forEach items="${infoModel.list["index"]}" var="qa" varStatus="rowCount">
<div class="question">
<h4><c:out value="${question.questionInfo.description}"/> </h4>
<form:radiobuttons path="list["index"][${rowCount.index}].answerId" itemValue="answerId" itemLabel="answerDescription" items="${question.answers}" delimiter="<br/>" />
<br>
</div>
</c:forEach>
Could you please suggest how i could try this one out?
NOTE: The same code works on a regular form submit on click of a button of type submit. Its the javascript form submit which is not working. I also tried to do whatever i want to do in javascript and then invoke the button.trigger('click'); form got submitted but the changes made on form in my javascript didnt reflect.
With commandName inside a form:form tag you set "Name of the model attribute under which the form object is exposed" (see Spring Documentation). Then in path you should tell the continuation of the path inside the model attribute.
With this said I would only drop the extra word infoModel from path="infoModel.answerId" and have it rewritten as path="answerId" there under the form:radiobutton.

mark only one checkbox?

I have a problem with checkbox. I have a list of checkbox, and I want to mark only one check and unmark other.
I want do that this in the same view , is it posible?
How can I do that?
<div><input type="checkbox" id="<%= id %>" onchange='submit();'/> </div>
thanks
Sounds like you really need a radio button instead. Radio buttons are mutually exclusive if you give them the same name:
<input type="radio" name="something" ... />
<input type="radio" name="something" ... />
If you really want checkboxes you will have to write some JavaScript logic.
Use radio buttons, not checkboxes.
<div>
foreach (var foo in model.Foos) {
<input type="radio" name="foo" id="foo_#foo.Id" value="#foo.Id" />
<label for="foo_#foo.Id">#foo.Value</label> <br />
}
</div>
Something like that should create a list of radio buttons.
Also, why are you submitting when the selection is changed? You should be using jQuery to do any selection-based manipulation to the page on the client side.
You could use jQuery. on document.Ready you'll have to bind a change event on checkboxes to some function, then in your function you want to reset all other checkboxes. That's assuming you don't want to use radio buttons as suggested above.

Resources