How to make a jsgrid select field with autocomplete, showing the label but returning the value - jquery-ui

In jsgrid I'm trying to transform a regular type:select field into a autocomplete field, using https://codepen.io/beaver71/pen/rpaLEo as an example.
BUT how to transcribe this so that the form shows the labels but transfers the values to the database?
using:
var tags = [
{label:"tag1", value:"201"},
{label:"tag2", value:"202"},
{label:"tag3", value:"203"}
];
instead of the default:
var tags = ["tag1", "tag2", "tag3"];

Related

How to get input box (filterbox) values from ui-grid column header

I'm trying to get the input box values present in the ui-grid column header.
I'm trying to use my own filtering function which requires to get values from multiple input boxes in the column header.
$scope.gridOptions.columnDefs = [
{
field: 'name',
displayName: 'Name',
headerCellTemplate: '<input type='text' disallow-spaces placeholder='Enter to Search' ng-model='testCol' id='Enter to Search'>},
];
You can give your custom filter to the columnDef like this:
$scope.gridOptions.columnDefs = [
{
field: 'name',
displayName: 'Name',
headerCellTemplate: '<input type='text' disallow-spaces placeholder='Enter to Search' ng-model='testCol' id='Enter to Search'>,
filter: {
type: uiGridConstants.filter.INPUT,
condition: myCustomFilterFunction
},
];
and your filtering function will look something like this:
function myCustomFilterFunction(term, value, row, column){
//do something here
}
uiGrid will call the myCustomFilterFunction everytime the filter input changes. The parameter term refers is what you were looking for. It's the value present in the input box. Parameter value refers to the value of the column for the current row. Parameters row and col give you access to the current rowEntity and column.
myCustomFilterFunction should return a boolen. If the returned value for a row is true then the row is displayed otherwise not.

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(){...});

Jquery UI autocomplete with value label pairs

I would like to set the source of autocomplete to the one that can have value/label pairs as described in their documentation here
http://api.jqueryui.com/autocomplete/
They say that
An array of objects with label and value properties: [ { label: "Choice1", value: "value1" }, ... ]
The label property is displayed in the suggestion menu. The value will
be inserted into the input element when a user selects an item. If
just one property is specified, it will be used for both, e.g., if you
provide only value properties, the value will also be used as the
label.
In my code I have
html
<input type="text" id="testBox" name="testBox" maxlength="70"/>
in my js
var catsArr = [];
for (var i = 0; i < 10; i++) {
var cat = {
label: "grey " + i,
value: i
};
catsArr.push(cat);
}
//tie the autocomplete to the box
$("#testBox").autocomplete({ source: catsArr });
But somehow, when the user starts typing the word grey, nothing shows up....What am I missing?

Processing multiple select controls within jquery mobile form

I am trying to process multiple input selects in a form each one has a unique name and id.
here is my first try, this is broken when y = value.val(); executes
var selects = $("#pmWorkOrderProcedureStepsForm").find('select');
$.each(selects,
function(index, value)
{
y = value.val();
});
I can see in chrome debug that value has a reference to something that looks like
HTMLSelectElement#select-choice-400139826
Where select-choice-400139826 is my first select input name.
How do I get just the name and the selected value of the input from here.
New to jquery mobile!
You can use the following code snippet:
var selects = $("#pmWorkOrderProcedureStepsForm").find("select");
$.each(selects,function(){
name = $(this).attr('name');
value = $(this).val();
});
A demo here - http://jsfiddle.net/5xg6F/
Let me know if that helps.

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