How to set dynamic value on react hook form? - react-hook-form

I am trying to take the email value dynamically from user on react hook form. but after hitting the submit button, all the field value available but email value undefined. I am adding the email field code here. Thanks in advance. <input className='mb-3' placeholder={user.email} value={${user?.email}}type="email" {...register("email")} readOnly disabled />

Related

Clear a field of an existing record while accessing the form

When accessing a form I need to add a field that has to be empty even if in the backend it has value. And when the user enters a value in this field, this newly entered value should replace the old one when the form is submitted.
The code below presents my best attempt, but onload doesn't do anything here for some reason. On the other hand if I use onclick the value is cleared as soon as the field is clicked. Could you please point me to right direction on what I am doing wrong with onload or if there's alternative solution to achieve the same need?
<g:textField
class="internal-text"
name="Internal__c"
value="${Instance?.Internal__c}"
onload="if (this.value != '') {this.value = '';}"
maxlength="20"/>
Thanks!
I'd suggest adding a hidden field and use a dummy text field to set it. The text field can be blank as desired, and when it changes you copy the value to the hidden field.
<g:hiddenField name="Internal__c" value="${Instance?.Internal__c}" />
<g:textField class="internal-text" name="Internal__c_dummy" onchange="this.form.elements['Internal__c'].value = this.value" maxlength="20" />

Grails formRemote disabled field content isn't coming back as a param from GSP

I am showing a text field on a GSP template that is in a formRemote and has content auto populated and is disabled (no editing allowed to user). When the form is submitted, I don't see the content of this field among the params going to the controller. I do see it when I remove the disabled="true" attribute from the text field. Any way to resolve this? Here is the field in question:
<label>Secondary ID:</label>&nbsp<g:textField name="secondaryId" disabled="true" style="border-radius: 5px" value="${recordToEdit ? recordToEdit.secondaryId : '' }"></g:textField>
Disabled form elements do not get submitted by the browser. You will need to enable the field(s) (through use of Javascript) prior to submitting the form.

change default behavior of unobtrusive jquery validation to validate on onkeyup?

I'm using micrososofts unobtrusive jquery validation with MVC4 / razor and the default behavior appears to be to first validate on click of submit, and then after that validate onkeyup.
I'd like to change it so it starts validating onblur, and then after the first submit continues to validate on keyup as normal.
Is there a way I can change it to start validating on blur for all forms?
This is the default behaviour when using jquery validate directly or via Microsoft unobtrusive validation. If you enter a non valid entry into a field, that field will be validated on blur even before the field is submitted. If you focus and then blur a field without entering anything this field will only be validated on submitting the form.
From the documentation page section "A few things to look for when playing around with the demo"
Before a field is marked as invalid, the validation is lazy [but] if
the user enters something in a non-marked field, and tabs/clicks away
from it (blur the field), it is validated
I have forked the fiddle in the comment to demonstrate this using the unobtrusive plugin and some rendered html. http://jsfiddle.net/8wkS2/
"Links to jsfiddle.net must be accompanied by code." so here is the rendered markup produced by the server
<input type="text" name="field1" id="field1"
data-val="true"
data-val-required="This field is required"
data-val-length="The field LastName must be a string with a minimum length of 5."
data-val-length-min="5" />

How to implement a toggle button to set a Rails boolean field

I have a Rails form with a checkbox on a boolean field.
I want to replace the checkbox with a toggle button, using Twitter Bootstrap.
Is there anything baked into Rails to provide this kind of functionality? Or will I need to write a script to update the checkbox value when the toggle button is clicked?
Thanks for any pointers. After a lot of searching, I've been unable to find anything that describes this.
At this point in time, the toggle Bootstrap buttons do not have the correct markup to work out of the box with forms (source).
You can wrap around the controls to insert the correct values into your parameters map using hidden fields. If you're using AJAX requests, you can simply include them in your parameters there.
In the case of the single toggle, you could implement a function as simple as this to set the hidden value.
In your form:
<input name="toggled" value="false" />
Evaluated before submission:
function isToggled() {
$('input[name="toggled"]').value($('#toggleButton').hasClass('active'));
}

clear all input components

I have 1 jsp form whcih take user detail and after clicking on submit button its store the data into DB and success message is displaying on the top of the GUI
but the problem is all the data iin the input boxes are not clear, data remain same in the input boxes
i m using struts2
can any body tell me how to clear all input boxes
Thanks
shakil
One option is to use a javascript to reset the form when the user clicks on submit. To do this, add the following javascript to your submit button (change 'form' to be the name of your form):
<s:submit value="Save" onclick="this.form.reset();" />
You could also use the Struts 2 JQuery Plugin which has a special tag for this purpose.
Better You set the the null value in model object in Action class of after store the data in DB and before return success
example if you have User object , you set user.setUserName(""); user.setPassword("")

Resources