Prototype 1.7: Is there a way to serialize elements outside of form? - prototypejs

In Prototype, is there a way to serialize all 'input' elements on the page after looking up using $$? I have to work with some pages that don't have any forms or some elements are outside of form hence cannot use Form.serialize or Form.serializeElements.

Actually you can use Form.serialzeElements() outside of a form you just need to pass it a list of elements.
For example
HTML
<input type="text" name="a" id="a" value="12345" />
<input type="text" name="b" id="b" value="6789" />
Javascript
Form.serializeElements($$('input'))
returns
a=12345&b=6789
try it out in this jsfiddle http://jsfiddle.net/av5Kj/

Related

Struts 2 validation resets my dynamic data

I'm trying to validate a form and it works well, the right messages appear...
My only problem is that my form fields are deleted if there are some errors.
Datas are taken by Database and be showed in forms with struts tags (so they're dynamic). If I put sono static value, that will not deleted after a wrong validation.
<s:form action="updateUser" method="post" id="updateUser"
name="updateUser" >
<s:textfield value="%{user.name}" class="modify" id="name" name="name" key="modify.name" required="true" />
this will be deleted while this:
<s:textfield value="HELLO" class="modify" id="name" name="name" key="modify.name" required="true" />
will not.
Any advice?
Have you set a User object in your Action Class? Do you have getters/setters for that object? Also how have you configured the "input" result of this action in struts.xml? Maybe you should use "chain" in result of INPUT (i guess this is the result you get from the validator.)

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.

How to execute code after the jquery.validate validation event?

I am using jquery.validate 1.9 and wish to execute code every time the form automatically validates (using the default behavior).
I hoped there would exist an OnValidated event I could hook into, but can not find one.
After validation executes I wish to conditionally enable other parts of the page if the form is valid, and disable otherwise.
How would one go about adding a method call following the existing validate() function?
I'm using jquery validate 1.8.1, but you should still be able to accomplish this using the valid() function.
valid() will either validate the entire form if you pass it the form ID or individual fields if you pass their respective ID's. It will then return a Boolean based on if they are all valid or not.
Something like this should work:
<script type="text/javascript">
function tab1Validation(){
if($('#field1, #field2, #field3').valid()){
//Logic if all fields valid - eg: $('#NextTab').show();
}else{
//Logic if one or more is invalid
}
}
</script>
<form id="yourform">
<div>
<input type="text" id="field1" name="field1" />
<input type="text" id="field2" name="field2" />
<input type="text" id="field3" name="field3" />
</div>
<input name="nextTab" type="button" value="Next Tab" onClick="tab1Validation();" />
</form>

Adding HTML5 placeholder attribute to spring 3.0 form input elements

How do I add HTML5 placeholder attributes to Spring webmvc's form:input, form:password and form:textarea elements?
As of Spring 3.0 form tags support dynamic attributes, therefore you can simply write
<form:input placeholder = "..." ... />
Regarding the new input types question - I had success by using spring bind and manually generating the input element. I'm using bootstrap so I already had a tag to wrap the control-group and apply the error message, but if you just want to inline it you can do the following.
if your path field was 'age', replace <form:input path="age"/> with
<spring:bind path="age">
<input id="age" name="age" type="number" value="${status.value}" />
</spring:bind>

Inject I18n text into javascript using tapestry-3

I'm adding Internationalization to a tapestry app.
Is there a standard tapestry-3 technique to Internationalize strings that appear as Javascript literals?
For example:
<input jwcid="submitBtn" type="submit" accesskey="U" value="Update" class="actionBtn" onclick="return confirm('Are you sure that you want to do that?');"/></td>
Can I simply replace the question with a tapestry tag in this and any other context? Say something like:
<input jwcid="submitBtn" type="submit" accesskey="U" value="Update" class="actionBtn" onclick="return confirm('<span key="AreYouSure">Are you sure that you want to do that?</span>');"/></td>
This means that the source file contains an element inside an attribute which would be fine inside a JSP. Does tapestry-3 handle this? If not, is there a way to do this in tapestry-3?
This works fine in T3 as well - another option is to initialize your i18n js strings at the top of the page:
<script>
var jsStrings = {
sure : '<span key="AreYouSure"/>',
...
};
</script>
and then just use them:
<input jwcid="submitBtn" onclick="return confirm(jsStrings.sure);"/>

Resources