I have a form with some text fields(mostly date fields) disabled for a particular user,but has got some value in it.I am not sure whether it is a read-only field.
anyway the thing is I want to access the disabled field value to perform some other operation using javascript
Here's the stringified value of the control
{"idbase":"row-4-cell-3","lock":{"vary":0,"fixLock":1,"hidden":"","epmSourced":1},"desc":"Plan_date_ac","name":"date-4-3","lockValue":null,"type":"AC"},
I tried using:
form[var.control).value
and:
document.getElementById(controls[var].idbase).innerHTML
neither works for me, it keeps throwing 'undefined'.
Note: only javascript, no jquery please!
That's a class. To get class data with Javascript. Used below code
var x = document.getElementsByClassName("example");
x.value // to get the x value
x.innerHTML // to get the content inside the element
Refer:
https://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp
Related
I am trying to manipulate a row using javascript in an older version of pentaho 4.4) and getting some strange results that I can't explain / don't understand what Pentaho is doing
var test = 'field';
Alert (this[test]); //--> Undefined
Alert (this['field']); // --> Expected result
Alert (this[test]); //--> Expected Result
For some reason, the initial request for this[test] is undefined until I use the literal string reference making it impossible to dynamically drive the process (i.e. I can't access row information by references).
Any ideas as to why? Is it simply how Pentaho deals with variables? Effectively I want my end result to allow me to change the row value at any given position. Either:
row[test] = 'New value
or
this[test] = 'New Value
or
this[test].setValue('New Value');
However, none of the above work, without replacing the values making it a very static process.
As far as I can see, Kettle does not add a field to the script's scope, unless the field is contained as a substring in the script source code (it should add even if the field mentioned in the comment). See determineUsedFields() and addValues() methods (https://github.com/pentaho/pentaho-kettle/blob/4.4.0/src/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L106).
So, the exact script you've provided, actually, produces either three defined values, or three undefined values, depending on whether the field exists or not. I was able to reproduce your issue only after I've removed strings with the field name from the code completely, and passed the field name in another field.
So, one way to manipulate row values could be to mention all field names in the script (e.g. in a comment), then try to use setValue as you have tried (seems to work in compatibility mode only).
Another possible way is to use the row array variable to get values and getInputRowMeta().indexOfValue(fieldName) to get the index of the field, e.g:
var idx = getInputRowMeta().indexOfValue(fieldName)
// WARNING: you may assign value of any type this way
// and the value will not be converted to a type defined
// in the field's ValueMeta:
row[idx] = 'New value'
However, this approach bypasses type conversions, which are usually performed while passing JavaScript values outside of the JS step in getValueFromJScript() method.
For example, the following code will put invalid value in the output, and you may not even notice it until some subsequent step will handle the value in some improper way:
// Let's assume that fieldName is name of the 0th input field.
// I'd expect, that the value would remain the same
// but in fact the `fieldName` references some wrapper oject
// which looks similar to its value
// but has a different type
row[0] = fieldName;
In subsequent JS step:
for(var i = 0; i < row.length; i++) {
Alert(row[i]) // alerts same value as the input, e.g. 'test'
Alert(row[i].class) // alerts undefined. While expected is 'java.lang.String'
// Some other subsequent steps may crash once this value encountered
}
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.
That's the html for the input field:
<input id="sku_input_field" type="text" name="items[0<?php echo $uniqueSuffix; ?>][sku]" class="input-text" />
And the javascript code that I am trying:
$('sku_input_field').value = jsonResponse.sku;
document.getElementById("sku_input_field").value = jsonResponse.sku;
So, you see, I am trying 2 approaches, and it doesn't work. I use FireBug to check and the response is NOT empty. I can see all the values that I am setting into it. The value of the field though still remains the same as the one I am typing.
It is that I type an id, and when the object with that id is found in the database I return a json response with some values (this happens in PHP). And one of these values, in the json response, is the one I want to set as a new value of the input field.
The value of the sku attribute is what I want to set as value of the input field. As you see, the response is not empty.
Should be :
jQuery
$('#sku_input_field').val(jsonResponse.sku);
// Provided jsonResponse.sku is not empty
// Also make sure jquery library is added.
Pure Javascript :
document.getElementById('sku_input_field').value = jsonResponse.sku;
p.s : Please check whether you are using same ID for any other element. ID needs to be unique.
I am on CakePHP 1.2 at the office and, following my last question, I would like to send the array key of the selected option in a SELECT input instead of sending its actual value. I have tried a few things with the Model::beforeSave() function, without success.
I am aware that the data posted by CakePHP does not include the whole array, but only the selected value.
Here is what the function looks like at the moment:
function beforeSave(){
$this->Post->set('category_id', = array_keys($this->data['Annonce']['category_id']);
# debug($this->data);
}
Would there be a way to store the array keys into an hidden input and changing this input value depending on the user's selected item in the SELECT input, and to also omit sending the user's input but still send the hidden value?
$categories = Set::combine($categories,'{n}.categories.id', '{n}.categories.nom');
This did it for me... CakePHP assigns the array_keys() values automatically to the value field of the input.
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