I'm pretty inexperienced with JavaScript, but I'm trying to do something that seems like it should be simple. I have a text input field (FieldA) in a FormAssembly form. I have another text input field that’s a calculated field (FieldB), and I want FieldB to return one value if FieldA is empty and a different value if FieldA is not empty. The formula I’m using in “Enter the calculation” looks like this:
if(FieldA==""){"empty"}else{"not empty");
When I go to the form, the result is “error” in FieldB, and adding a value to FieldA has no effect. When I do it in Preview mode, I get the additional message “There was an error computing this field.” FieldA here is tfa_40, but it seems to make no difference whether I use tfa_40 or define it as a variable and use the variable name. It also doesn’t seem to matter whether I use double quotes, null, or 0. Am I taking the wrong approach here? Is this even possible?
Related
I have a model, and it can take one of two forms:
{
"x-position" : "center"
}
or
{
"x-position" : 20
}
Notice how in the first example, x-position is a string, while in the second it is an integer. These values are bound to an HTML input of type text. I can't use input of type "number" because then it would error if it tried to interpret "center". Therefore, I must use text.
If we look at the second example, if the user changes the value to 25, since the input html element is of type text, my model is now:
{
"x-position" : "25"
}
The issue is the text input has now changed the value type of x-position in my model from an integer to a string (20 to "25"), which is undesirable. This is because I'm forced to set the input type to "text", even though I want to allow both text and number, which is impossible. I wouldn't mind accepting only string, as long as I'm able to manipulate the string somehow and convert it to number before passing it back to my model.
Is it possible for me to add an additional layer of logic between the view and model, such that if a user inputs a value "25px", I can then strip out the "px", and then parseInt("25"), then pass this value into my model as an integer...does such a thing in Angular exist?
One approach that I've tried was I set up a $watch on x-coordinate, and added some logic when the value changes via user input. This works on a small scale for predictable data. However, the issue with this is that my model is dynamic, constantly changing, and it could have hundreds of "x-positions" that I would have to watch. Adding a watch to such a large amount of dynamic data seems unfeasible to me...unless I'm mistaken.
Thanks
I think you have 2 approaches here:
If you only need to convert to a number when you save the data, then just convert it once, when you save
If you really have to convert it every time the user changes the input (although I don't see a case where it would be required), then you can either define a watch, as you already did, or you can put ng-change or ng-blur on the input. (which will eventually also define a watch, but at least that way you have more control on what you pass to the function)
I'm looking to have both value and placeholder at an input field... the value would be more like twitter's #mention... it's the text the user need to have to start the input, and the placeholder gives hint to what user needs to type.
It seems like this can't be accomplished with only html
But is there anyway to make this possible in javascript or other means?
Use either two input fields (one with value and one with hint) or just use a label to tell the user the string always starts with #mention (or something else).
In the code to handle the input you then append both strings.
I have defined two Text input in my html like this..
<revit:validationTextBox id="viewEditParameterValue" maxLength="2500"
required="true"
invalidMessage="#{commonuielements.msg_invalid_input}">
</revit:validationTextBox>
<revit:validationTextBox id="viewEditParameterValDefault"
maxLength="100"
regExp="#{commonuielements.parameter_default_value_regex}"
invalidMessage="#{commonuielements.msg_invalid_input}"
trim="true"></revit:validationTextBox>
I am trying to get the value of two TextBox in a java script function like this..
var value = dijit.byId('viewEditParameterValDefault').value;
var parValue = dijit.byId('viewEditParameterValue').value;
But for the first one I get the value but second line returns blank whereas If I use below line I get the value.
var parValue = dijit.byId('viewEditParameterValue').get('value');
Does anybody have any guess what could be the reason?
get('value') is the correct way to retrieve the value of a Dijit form input widget. Accessing value directly isn't guaranteed to give you consistent results (or the results you expect), since it will be implementation-dependent. This is perhaps even more important for certain subclasses of TextBox where formatting or mapping come into play.
Moreover, setting value directly won't accomplish anything, whereas calling set('value', ...) will properly update the widget.
I'm wondering why for some widgets such as the currency widget when I perform a dojo.byId to get a value of the textbox, I get back the formatted value meaning I get back something like this: "$44.3" with the dollar sign.
However when I created a custom percent textbox, and it inherits from the NumberTextbox (as so does the currency textbox widget), for some reason doing a dojo.byId returns me the value without the % even though I see there is a % in the textbox.
I'm trying to unit test this stuff and for some reason, for the currency control I was able to do something like this:
var formatedValue = dojo.byId("currencyTextBox").value;
doh.t(formatedValue === "$46.93", "incorrect formatting");
which when I check formattedValue it gave me "$46.93".
However when I tried this same type of deal with my percent textbox, if I see for example "55%" in the textbox, this will return 55, not "55%":
var formatedValue = dojo.byId("percentTextBox").value;
doh.t(formatedValue === "93%", "incorrect formatting");
so I don't understand why the behavior would act differently in terms of it picking up the textbox value using dojo.byId. (Obviously if I were to do a widgetInstance.get("value"); I'd expect only a whole number to come back, the raw number without the formatting.)
I'm looking for a way, with jQuery, to get the default value of an input field (in an HTML field).
Seems simple enough. Just calling $("#id-of-field").attr('value') should return the value I'm wanting right?
Thing is, if the value is Foo, when I load the page, it returns Foo. No problem there. But if I write Bar in the field, then reload (not submit) the page, $("#id-of-field").attr('value') will return me Bar, even if in the source code, the value attribute of the field is still Foo.
That makes validation of my form sticky, because when I get my default values to ignore them if the field has not been filled, I could get a real value in the mix of "Values to be ignored".
FYI, I can't put in the values manually, since the form is dynamic, and cannot query directly the database because it's a Wordpress Website.
Input fields have the defaultValue DOM property that does exactly what you need.
According to this answer, the jQuery (> 1.6.3) way to access it is
$('#element').prop('defaultValue')
Alternatively, in pure JavaScript, e.g. -
document.getElementById("element").defaultValue
Try this
$('inputSelector').prop('defaultValue');
You could try -
$("#id-of-field")[0].defaultValue
That should get the DOM defaultValue property which should give you the original value of the textbox
https://developer.mozilla.org/en/XUL/textbox#p-defaultValue