This is my form input field (without classes and such):
<input id="input_partnerID" type="value" name="partner_id" value=""/>
I want to set the input value to the contact id of the logged in user. I can get that value with this Qweb code:
<p id="value_parterID" t-esc="user_id.partner_id.id"/>
And to get that value in my input form I use this javascript. The method is called when the "accept terms and conditions" button is clicked.
function getID() {
document.getElementById("input_partnerID").value = document.getElementById("value_parterID").innerHTML;
}
This works but probably isn't the most efficient way to do this.
How can I use Qweb to fill in the input value in 1 or 2 lines preferably without javascript?
You can set the attribute value using t-att-value="".
So in my case I should use this input field:
<input type="value" name="partner_id" t-att-value="user_id.partner_id.id"/>
Which does the same as the given example with the <p> and javascript.
J'm trying to pass some data from javascript to #ENV in hidden input value, in CVT form.
In the form i have some radio inputs which are working fine and one hidden input to get the leaflet coordinates stored in js variable.
My input looks lick that:
<input value='#ENV{localisation, #GET{coord}} 'name="localisation" type="hidden"></input>
and my code:
[(#SET{coord, JSON.stringify(latlng_tab)})];
In the
console.log (#ENV{localisation, #GET{coord}})
I can see the coordinates but it doesn't work in input.
Can someone help me, please.
In case someone will be looking for an answer.
I had to remove #GET from input and #SET from the code and instead i'm using that:
<input id="localisation" value='' name="localisation" type="hidden">
</input>
var latlng_str = document.getElementById("localisation");
latlng_str.value = JSON.stringify(latlng_tab);
I have a simple yesod form:
aYesodForm :: Form Text
aYesodForm = renderDivs $ id
<$> areq hiddenField "" Nothing
It generates roughly:
<input type="hidden" id="h2" name="f2" value="">
I want to fill it from javascript like:
document.getElementById('h2').value="foo"
But it would be bad practice to hardcode 'h2' into the .julius file, as it is auto-generated and could change.
the return type of runFormPost does not return the field ids it has generated, to interpolate into the .julius file.
What is the best way to fill yesod generated form field in javascript?
You should be able to create your own ID when you generate your form using the FieldSettings parameter. FieldSettings data type can be found here: http://hackage.haskell.org/packages/archive/yesod-form/1.3.0/doc/html/Yesod-Form-Types.html
Something like this (untested):
<$> areq hiddenField (FieldSettings (SomeMessage "") Nothing (Just "myId") Nothing []) Nothing
I'm trying to make an Angular.js app that creates dynamic form inputs from a JSON object.
So firstly, I have a JSON object (called fields):
[
{"field_id":209,"form_id":1,"name":"firstname","label":"First Name","type":"text"},
{"field_id":210,"form_id":1,"name":"lastname","label":"Last Name","type":"text"},
{"field_id":211,"form_id":1,"name":"email","label":"Email","type":"text"},
{"field_id":212,"form_id":1,"name":"picture","label":"Picture","type":"file"},
{"field_id":213,"form_id":1,"name":"address","label":"Address","type":"file"},
{"field_id":214,"form_id":1,"name":"password","label":"Password","type":"password"},
{"field_id":215,"form_id":1,"name":"","label":"","type":"submit"}
]
The object key type is the input type for a form. See below:
<p ng-repeat="field in fields">
{{field.name}} : <input type="{{field.type}}" value="{{record.data[field.name]}}" />
</p>
Now this works completely fine for submit, text, password, checkbox and radio fields. But if the type is file, it sets the input type to text.
If I replace {{field.name}} with {{field.type}} for the text, I can confirm it is outputting file.
If I statically change <input type="{{field.type}}"... to <input type="file"... it will display a file input correctly.
Why won't it let me set an input type as a file dynamically?
Topic if changing type property if <input> element is hot topic.
Actually, as AngularJS behaviour depends on was jQuery added (before or after angular.js).
Here you can read some discussion about possibility to change type:
change type of input field with jQuery
Also there is pull request to AngularUI for adding new directive with support of dynamic type change: https://github.com/angular-ui/angular-ui/pull/371
If you find suggested solution is not good enough (though as type is not changed after you render form) you can go with ng-switch way - just show corrent input for user.
I am trying to grab text generated by javascript and paste it into a forms input value field. This is what I have so far:
var txt=$('#grabemail').text();
$('#email').val(unescape(txt));
<p id="grabemail" style="color:#fff;">
<script type="text/javascript">formData.display("email")</script>
</p>
The only problem is that when the jQuery grabs the text from #grabemail it not only takes the email but it also takes 'formData.display' so I end up with:
formData.display("email")user#email.com
In the field as opposed to just the email.
I cannot edit the JS inside of the #grabemail div.
Anybody have any ideas on how to fix this?
var txt = unescape($('#grabemail').text());
$('#email').val(txt.replace('formData.display("email")',''));
have you tried this way?
txt=txt.substring(25, txt.length);
This should work.