adding an id attribute to q-input - quasar-framework

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

Related

What is the equivalent of HTML'S input tag in Rails?

I want to be able to generate this
<input id="address" type="textarea" value="Write your Address here.">
Using some ruby form helpers.
Any hints ?
I assume you meant textarea since there is no such thing as textbox.
http://apidock.com/rails/ActionView/Helpers/FormTagHelper/text_area_tag
if it's not tied to a field in your model
http://apidock.com/rails/ActionView/Helpers/FormHelper/text_area
if it is.

Rails form helper: Override id of Rails hidden model id

According to the docs for Form Helper's form_for:
The form_for method automatically includes the model id as a hidden
field in the form. This is used to maintain the correlation between
the form data and its associated model. Some ORM systems do not use
IDs on nested models so in this case you want to be able to disable
the hidden id.
This makes sense and is important, but if you have two form_for calls on the same page, it generates two hidden fields with the same markup and the same id. In my case, it generates this twice on the same page:
<input id="clinic_patient_signup_clinic_patient_link_person_attributes_patient_information_attributes_id" name="clinic_patient_signup[clinic_patient_link][person_attributes][patient_information_attributes][id]" type="hidden" value="32" /></div>
Is there a way to overwrite the id attribute of that input? If I remember correctly, it's just the name attribute that is important, and the value can stay the same. Our site has to be WCAG 2.0 accessibility compliant, and it won't allow two tags on the same page with the same id. (That's also not valid HTML.)
Use the form_for :namespace option.
See https://stackoverflow.com/a/26415985/2511083 for a complete answer.

Not sure if I have an issue with blank constraint or Dynamic Scaffolding

I have a simple Domain class that has a few properties. I want to allow one of them to be empty. I am using blank:true in my constraints block.
In Config.groovy I have set convertEmptyStringsToNull=false. That I believe will keep my form submission from setting the blank field to null and the submit failing on the implicit nullable check.
I am using Dynamic Scaffolding in my controller.
I have added some data via BootStrap.groovy. One record has a blank field and it saves as I would expect.
I then launch my app and the list shows my bootstapped records, including the one with the blank field.
When I try to create a new record, with the property that accepts blanks, I am getting a "Please fill out this field" validation error. I believe the record should save.
I'm not sure if this is an issue with the scaffolded view, an issue with the blank constraint, or me not understanding how these features should work.
Any help would be appreciated.
I guess your entry in Config.groovy is:
grails.databinding.convertEmptyStringsToNull = false
The scaffolding plugin does not take this configurationoption into account and the scaffolded view _form.gsp contains a required="" attribute
<g:textField name="name" required="" value="${fooInstance?.name}"/>
You need to remove
required=""
resulting in
<g:textField name="name" value="${fooInstance?.name}"/>
so that the browser lets you enter an empty value.

Creating objects with hidden field values passed from Rails

Im quite new to Angular, so how Im approaching this might be entirely wrong, but some general advice on which direction to take with this would be much appreciated. More or less what I'm trying to do is use Angular to create new "Like" objects (similar to facebook 'likes'). They contain two values, user_id (which used to be set by rails as current_user.id via devise's helper method) and post_id.
My problems:
current_user is not accessible in Angular's ng-controller
You can't provide default input values directly into the form like so:
`
<input type="text" value="<%= current_user.id %>" ng-model="newLike.user_id" >
So more or less what I'm asking is, how could I manage to set default values of the inputs for user_id and post_id. I've come across recommendations for using ng-init, however, from everything I've seen it seems that this only allows setting default input values from the angular controller
EDIT:
It took shockingly long for it to dawn on me to pass the variables in as params to addLike so I've managed to successfully create new objects based off of the current_user.id & act.id.
Rails way
You can write inside your .html.erb (or .js.erb) javascript code that initializes a global / passes a parameter with the value of current_user.id
Angular way
Using ng-init is perfect here (better over the rails way). As Mark Rajcok commented ng-init can be used from your HTML like this:
<input type="text" ng-init="newLike.user_id='<%= current_user.id %>'" ...>

Rendering html using Struts2

Using Struts2, my goal is to present a simple blog to a user using Struts2 iterators, such as:
Most Recent Topic
response 1
response 2
...
Previous Topic
response 1
response 2
...
Users generate and submit each Topic/Response using a separate form, but, once submitted, I don't want them to edit the blog.
To generate either a Topic or a Response, I provide an editor (like the stackoverflow editor I'm using now) that produces html-formatted text, including whatever styling (bold, underlines, lists, etc.) that the user chooses. The text of the Topic/Response created by the user, including the html tags, is stored in a database.
However, I cannot find a way to render the Topic/Response as html in the blog. For example, text bolded in the editor shows up as <strong>text</strong> in a struts2 s:textarea tag.
I know that the s:property tag has an 'escapeHtml' attribute that will prevent this, but the s:property tag can't layout the text properly, and it seems that only the s:property tag has this attribute.
I've tried using <input value="%{#topic.content}" /> within the iterator instead of s:textarea, but it doesn't seem to recognize the #topic iteration reference.
Is there a way to do this?
use text instated of tax area .Let me know if you still facing this issue.
Use escapeHtml="false". I just tried it myself and it works as intended.
For example, with:
<s:set var="var1"><p>some stuff</p><p>other stuff</p></s:set>
<s:property value="var1" escapeHtml="false" />
renders the paragraph tags as you would expect.
How about using <pre> with <s:property>.
About html <pre> tag:
http://www.w3schools.com/tags/tag_pre.asp

Resources