How to dynamically add attribute and value to E4X object in Javascript(Compiled on Rhino)? - rhino

I want to create an e4x object.
The I want to dynamically keep adding attributes for it and also add value later.
e.g
var node = <node />;
//some code
1) add attribute to 'node'
2) add value to 'node'
Also I found such examples for Flex3 but none for Javascript. Any further documentation would also be appreciated

if you want to add an attribute or value
var node = <node/>
node.#id = 123
node.toXMLString()
//returns
//<node id="123"/>
if you would like to add attributes named dynamically then use the square brackets
node.#["prioritory"] = "high"
//returns
//<node id="123" prioritory="high"/>
the same works for adding child elements
node.description = "Warning"
node.toXMLString()
//<node id="123" prioritory="high">
// <description>Warning</description>
//</node>
node["location"] = "R23"
node.toXMLString()
//<node id="123" prioritory="high">
// <description>Warning</description>
// <location>R23</location>
//</node>
I find this link helpful when trying to refresh my e4x http://wso2.org/project/mashup/0.2/docs/e4xquickstart.html

Related

React-Final-Form -> Dynamically created from based on data from server

EDIT: THE IDEA BELLOW WORKS
I just noticed that the problem was in . notation of values I used. The path must be correctly converted to the same object structure as in case of tools changeValue).
Also, this code
...
const initialValues = form.getState().initialValues;
initialValues[fieldName] = fieldValue;
form.setConfig("initialValues", initialValues);
...
had to be changed to
...
const initialValues = form.getState().values;
initialValues[fieldName] = fieldValue;
form.setConfig("initialValues", initialValues);
...
as I wanted current values to be kept in the form instead of the form has to be "reinitialized".
I am using final-form for presenting a form partly generated dynamically based on the data templates and the data itself loaded from the server.
In order to generate the form and populate it with the values loaded from the server I am using custom mutator, which just sets the correct values once the form is generated and the data is loaded from the server.
Mutator works well, but I also need to set initialValues once the part of the form (based i.e. on initial value or user selected value of the combo box) is loaded and generated in order to prevent dirty state before the form is touched by the user.
Question: Is it possible to set initialValues dynamically, once the template/data is loaded in order to prevent pristine/dirty state, but also, without touching other form values and initialValues?
Please note, this is just example of children component used within the form declared in parent component (including the custom mutator). My original code is way too complex to pass it here. Maybe this code is not fully syntactically correct, maybe it would not work with checkbox, don't care too much about it - it is just an example and the question is about something else. Mutator works actually well, so please focus on initalValues.
interface Props {
fieldName: string;
fieldType: "checkbox" | "text";
fieldValue: string | boolean;
}
function DynamicFormField({
fieldName,
fieldType,
fieldValue
}: Props) {
const form = useForm();
useEffect(
() => {
// *** this is what I tried, but does not work ***
const initialValues = form.getState().initialValues;
initialValues[fieldName] = fieldValue;
form.setConfig("initialValues", initialValues);
// ***
// *** also tried ***
const initialValues = { ...form.getState().initialValues };
initialValues[fieldName] = fieldValue;
form.setConfig("initialValues", initialValues);
// ***
form.mutators.setValue(fieldName, fieldValue);
},
[fieldName, fieldValue]
)
}
return (
<Field name={fieldName}>
{({ input }) => (
{
fieldType === "checkbox" ?
(<input {...input} type="checkbox")
:
(<input {...input} type="text")
}
)}
</Field>
)
It works, please see edit.
The initialValues object must just have same structure as the values object.

jsViews dynamic linking to a different item in array

I am trying to have a dynamic if linking to a property of a different item in an array.
My current code:
Loader
for (...) {
var index = this.App.Data.Questions.push({
...
}) - 1;
if (CompareGuids(this.App.Data.Questions[index].QuestionId, '06EF685A-629C-42A5-9394-ACDEDF4798A5')) {
this.App.PregnancyQuestionId = index;
}
Template
{^{if ~root.Data.Questions[~root.PregnancyQuestionId].Response.ResponseText == "true"}}
{{include #data tmpl="Clinical-History-QuestionWrapper-SingleQuestion"/}}
{{/if}}
It works for the initial loading, but it does not update.
Note I assume I could achieve this with a boolean property in ~root, and then have a $.observable(...).oberserve(...) update this property, but I would prefer to have a direct access.
It looks like all you need to do is make sure that you are changing the PregnancyQuestionId observably. Just assigning a value cannot trigger data-linking to update the UI.
You need to write:
$.observable(this.App).setProperty("PregnancyQuestionId", index);
That should then trigger the binding correctly...

How to display previous value on Min Miles text field

I want to display a previous value on Min Miles and that should not be editable. I want like
Default value of Min Miles is 0.
When I click on Add More Range then In the new form - Min Value should be Max Value of Previous Form.
I am using semantic form for. Please Help Me. How can I do this...
Regarding your second question, and assuming that the new form appears through javascript, without page reloading, you can grab the
field value with javascript and use it as the default value for the
new field. The "add new range"
Something Like
function getvalue(){
var inputTypes_max = [],inputTypes_min = [],inputTypes_amount = [];
$('input[id$="max_miles"]').each(function(){
inputTypes_max.push($(this).prop('value'));
});
$('input[id$="amount"]').each(function(){
inputTypes_amount.push($(this).prop('value'));
});
var max_value_of_last_partition = inputTypes_max[inputTypes_max.length - 2]
var amount_of_last_partition = inputTypes_amount[inputTypes_amount.length - 2]
if (max_value_of_last_partition == "" || amount_of_last_partition == "" ){
alert("Please Fill Above Details First");
}else{
$("#add_more_range_link").click();
$('input[id$="min_miles"]').each(function(){
inputTypes_min.push($(this).prop('id'));
});
var min_id_of_last_partition=inputTypes_min[inputTypes_min.length - 2]
$("#"+min_id_of_last_partition).attr("disabled", true);
$("#"+min_id_of_last_partition).val(parseInt(max_value_of_last_partition) + 1)
}
}
I have Used Jquery's End Selector In a loop to get all value of max and amount field as per your form and get the ids of your min_miles field and then setting that value of your min_miles as per max_miles
It worked For me hope It works For You.
Default value of a field can just be passed in the form builder as a second parameter:
...
f.input :min_miles, "My default value"
Of course I do not know your model structure but you get the idea.
Regarding your second question, and assuming that the new form appears through javascript, without page reloading, you can grab the field value with javascript and use it as the default value for the new field. The "add new range" click will be the triggerer for the value capture.
Something like (with jQuery):
var temp_value = '';
$('#add_more_range').click(function(){
temp_value = $('#my_form1 #min_miles').value();
$('#my_form2 #max_miles').value(temp_value);
});
Again I am just guessing the name of the selectors, but the overall approach should work.
If you are also adding dinamically to the page the "Add new range" buttons/links, then you should delegate the function in order to be inherited also for the so new added buttons:
$('body').on('click', '#add_more_range', function(){...});

how to get the child names when i select the parent in the tree view

I am using kendoUI tree view with check boxes implementation.
I am able to check all children's check boxes,when i select the parent checkbox.
now,I want to get all the children's text values when i select the parent check box.
I used template for check box operation in tree view
$("#ProjectUsersTreeView [type=checkbox]").live('change', function (e) { var chkbox = $(this);
var parent = chkbox.parent();
var pBox = $(parent).closest('.k-item').find(":checkbox");
if (this.checked || pBox.length>0) {
$(pBox).prop('checked',this.checked ? "checked": "")
}
Instead of using your code for checking children I do recommend using KendoUI configuration option checkChildren.
tree = $("#ProjectUsersTreeView").kendoTreeView({
checkboxes:{
checkChildren: true
},
...
}).data("kendoTreeView");
Then for getting all selected text use:
$("#ProjectUsersTreeView [type=checkbox]").live('change', function (e) {
var checked = $("input:checked", tree);
$.each(checked, function(idx, elem) {
console.log("text", tree.text(elem));
})
});
In checked I get all input elements from the tree that are actually checked and display its text on console by getting it using text method.
NOTE: Realize that I've defined tree as $("#ProjectUsersTreeView").data("kendoTreeView") and then use it in change handler.

Update custom cascading select field in JIRA via suds

Using JIRA version 4.2. With Python 2.7 and suds 0.4, how can I update an issue's custom cascading select's field (both parent and child)?
There is a SOAPpy example available under "Python (SOAPPy) client".
I was unable to perform this type of update using the Python JIRA CLI.
Example:
When updating the cascading select custom child of parent field, customfield_10, one would want to update the field customfield_10_1.
Update
Code to display cascading field's original value:
issue = client.service.getIssue(auth, "NAHLP-33515")
for f in fields:
if f['customfieldId'] == 'customfield_10050' or f['customfieldId'] == 'customfield_10050_1':
print f
This results in:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
After manually setting the cascading field's child, the above code results in:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = "1"
values[] =
"11560",
}
The above values is what I hope to achieve via suds.
Note the key = "1" field. The key value designates that this object is the child of customfield_10050.
Documentation reference:
parentKey - Used for multi-dimensional custom fields such as Cascading select lists. Null in other cases
Let's try sending a key field value:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050_1", "key":"1", "values":["11560"]}
])
This results in an error because the updateIssue accepts a RemoteFieldValue[] parameter, not a RemoteCustomFieldValue[] parameter (thanks Matt Doar):
suds.TypeNotFound: Type not found: 'key'
So how do we pass a RemoteCustomFieldValue parameter to update an issue?
Update 2, mdoar's answer
Ran following code via suds:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050_1", "values":["11560"]}
])`
After value:
(RemoteCustomFieldValue){
customfieldId = "customfield_10050"
key = None
values[] =
"10981",
}
Unfortunately, this does not update the child of customfield_10050. Verified manually.
Resolution:
Thank you mdoar! To update a parent and child of a cascading select field, use the colon (':') to designate the child filed.
Working example:
client.service.updateIssue(auth, "NAHLP-33515", [
{"id":"customfield_10050", "values":["10981"]},
{"id":"customfield_10050:1", "values":["11560"]}
])

Resources