I've an input fields dynamically added multiple times in the form using jQuery. Onsubmit of the form, at the action side I'm getting "comma+space" separated request parameters & values as shown below,
<input type="text" name="chars" />
Action side --> chars=char1, char2, char3,......
to get the values I can split the string by comma(,), but this case fails if the user enters comma in the text fields. I cannot get the entered comma by any means.
Can anyone suggest on how to separate the values and get the comma as character as I've to store this in DB?
Related
Say I have the following q-input:
<q-input
v-model="form.email"
inverted-light
color="white"
stack-label="Email:"
type="email"
#blur="$v.form.email.$touch"
:error="$v.form.email.$error"/>
I'd like to be able to make it so that if the domain of the email is mydomain.com that the form action will change to another website (without csrf protection) and the POST will be made to that website instead of the main one.
To do this I was thinking I could use jQuery. eg. $('#email').val().replace(/^.+#/, '') == 'mydomain.com' then change the form action and submit.
The only problem is: I don't know how to set an id attribute on q-input.
Any ideas?
As of early Quasar 1.4.2 (November of this year) you can specify the id value on the resulting html generated by q-input by using the "for" property (see the end of the behavior properties: https://quasar.dev/vue-components/input#QInput-API).
So, for example, you could add for="myInputId":
<q-input
v-model="form.email"
inverted-light
color="white"
stack-label="Email:"
type="email"
#blur="$v.form.email.$touch"
:error="$v.form.email.$error"
for="myInputId"
/>
The id attribute with value "myInputField" will end up on the resulting <input> element in your HTML.
Not using the "for" in the elements gave me a lot of headaches because the Jest snapshot generated random IDs
I have a text field that accepts any number of rows of input, with four columns. Valid input might be:
1 2 3 A
3 4 2 B
1 3 2 C
etc..
Normally with ActiveBase, fields would be generated by whatever model that you have using the form_for method, however, I do not wish to do that here, because then the user would have to fill out a form for each row of input, then submit, when instead I just want the user to paste any number of rows, and press submit once.
After submitting, a service call will be made with a JSON representation of all of the models that were created. I figured that having this textarea populate N number of models would ensure validation, and I could easily throw out bad requests.
I am unsure how to parse and post this data in 'simple rails fashion', given that the form isn't generated using form_for and the fact that multiple of the same model can be created.
So the real question is, how do I structure this? What does my workflow look like?
Say you have a form you've written "by hand":
<form id="my_form" action="/my_endpoint" method="POST"
<!-- you need a line like this to PUT, DELETE, or PATCH -->
<input type='hidden' name='_method' value="PUT">
<!-- if you enabled csrf check -->
<input type='hidden' name='authenticity_token' value='<%= form_authenticity_token %>'>
<!-- a base input -->
<!-- send the param as an array by using [] in the name attribute -->
<input id="base_input" type='text' name='user_inputs[]'>
<input type='submit' value='submit'>
</form>
And you also have a button which adds an input to the form:
<button id="add_input">add input</button
You can write some jQuery to add fields to the form (this example is coffeescript):
# document ready block
$(->
$("#add_input").on "click", (e) ->
$form = $ "#my_form"
$baseInput = $ "#base_input"
$newInput = $baseInput.clone()
# clear entered text
$newInput.val ""
# remove base_input id
$newInput.attr "id", ""
# add the new input after the base input
$baseInput.after $newInput
)
In the controller, you'd have a params user_inputs which is an array of strings; what to do with this data is up to you. The base input can also be a different type (textarea, checkbox, etc) but in jQuery you'll have to use different javascript methods to clear their prior content.
I've got a form where I want to edit some user data.
So the already stored data is put as th:value and after sending I validate with spring validation and want to give back the form on wrong input. I want the input field to have the value of the input by the user but it always gives me the stored input instead.
That's how an input field looks like
<input type="text" th:value="${product.name}" th:field="*{name}" th:errorclass="fieldError"/>
If the form is loaded the first time the input fields should have the value of the already stored data.
If it's loaded after submit and with an validation error, the input fields should have the value of the user's input.
Is there a way to to that?
Thanks!
Attribute th:field will replace attributes value, id and name in your input tag.
Instead, use plain th:id, th:value and th:name without using th:field. Then you will get what you wanted.
Then it will look like:
<input type="text" th:value="${product.name}" th:name="name" th:id="name" th:errorclass="fieldError"/>
Similar answer is here: How to set thymeleaf th:field value from other variable
Because Attribute th:field is Combination of both th:name and th:value
So, either use this:
<input type="text" th:value="${product.name}" th:name="name" th:errorclass="fieldError"/>
Or this:
<input type="text" th:field="*{name}" "th:errorclass="fieldError"/>
Using th:field or value, id and name is ok. if you user th:field, you can write this:
<input type="text" th:field="${product.name}" th:value="${product.name}" "th:errorclass="fieldError"/>
You have error in your controller (you set wrong value to *{name}), if the input value is wrong after validation error.
Am passing a cxml document text from Servlet to JSP in struts2 and the jsp will submit form BODY onload with action = "to Second Project" also the same cxml text been passed in hidden parameter and its working fine, but when i try receive the value of parameter passed from first Project its in-complete only i have got first 15 characters -->
I think you are using you are using <input type="hidden" value="" /> and your parameter also got double quote. Try to user value=''
How do you set a string to denote the required format pattern in a text box. For instance, if I have a text box displayed such as a date field, how do I display a format of "dd/mm/yyyy" to help the User complete the field. If the field is already populated when the view is displayed then the actual data should be displayed.
If the field is a drop down list, I would like to display "Please select from the list" if the field does not contain a value.
In HTML 5 you can achieve it using Placeholder attribute of input tag like this:
<input name="email" type="email" placeholder="validemail#email.com" />
However HTML5 is not yet supported by most browsers, so you will have to live with javascript based solution. Populate the desired value in textbox when page is loading (you can use CSS to make that text dim). Using javascript empty the field on "onfocus" event.
For drop down list populate "please select..." thing with Value as 0. This way you can validate on server that user has not selected any valid value.