I inserted some company in form with AJAX and append response to select box.
Sometimes Response append to Select 1 and sometimes to Select 2 but not both.
## add_company my submit form for Insert Company##
## company my form for insert Company##
$("#add_company").on("click",function () {
var first = 1;
var active = false;
$(document).ajaxStart(function () {
active = true;
}).ajaxStop(function () {
active = false;
});
if (!active) {
var search = $("#company").serialize();
var option = "";
var option_text = "";
if (search != "") {
$.get("./json/company.php", search, function (data) {
$.each(data, function (index, value) {
option = document.createElement("option");
option_text = document.createTextNode(value.name);
option.appendChild(option_text);
option.setAttribute("value",value.id);
##companies is Select 1 company Warranty Select2##
document.getElementById("companies").appendChild(option);
document.getElementById("company_warranty").appendChild(option);
if(value.id) {
var msg = document.createTextNode("با موفقیت ثبت شد");
document.getElementById("message-succ").appendChild(msg);
$("#succes").show("slow");
} else {
var msg = document.createTextNode("متاسفانه ذخیره نشد!!!");
document.getElementById("message-dan").appendChild(msg);
$("#unsucces").show("slow");
}
})
}, 'json');
}
}
});
One child cannot have two parents, what you can do is
clone the child and append as a child to other elements
Related
On the click of submit button, I want to send all the data by ajax call to the server. I'm trying to get the selected Text of dropdown list, it gives the text of first dropdown list for each iteration.
JSFiddle https://jsfiddle.net/L7xy2kjz/10/.
This is the result of what I tried :
ScoreCard={"Heading":"pawar","parameters":[{"Name":"nikita ","Raiting":"ME","Score":"0"},{"Name":"mayuri","Raiting":"ME","Score":"0"}]},{"Heading":" schoool","parameters":[{"Name":"sss","Raiting":"ME","Score":"0"}]}
In the above code even after selecting the different options from the dropdown ie. "Raiting":"ME" . but the output displays the Text of first dropdown.
function GetObservationReview() {
var parameters = {}, status;
var ObservationArray = [];
$('#ObservationEntry, .tblObservation').each(function () {
var item = $(this).closest("tr").find('td'); //get each row
var hasclassparam = $(this).closest("tr").attr('name') === 'ObsevHeading';
if (status == 'Parameters' && $(this).attr('name') === 'ObsevHeading') { //if next tr is heading then push whole object in array till first heading
metrics = {
'Heading': Heading1,
'parameters': paramarray // paramNewArray
//work in process
}
var stringyfydata = JSON.stringify(metrics);
ObservationArray.push(stringyfydata);
metrics = {};
paramarray = [];
}
if ($(this).attr('name') === 'ObsevHeading') { //if the current row having name as heading
status == 'heading';
$.each(item, function (key, value) {
if (key == 0) {
Heading1 = ($(value).text());
}
//else if (key == 1) {
// TotalWeightage = ($(value).text());
//}
});
}
if ($(this).attr('name') === 'ObsvParameters') { //read parameters
status = 'Parameters';
var e = document.getElementById("dropDownLevelChangetrue");
var strUser = e.options[e.selectedIndex].text;
var islastchild = $(this).closest("tr").is(":last-child"); //last child
MyLevels = {}; i = 1;
$.each(item, function (key, value) {
if (key == 0) {
parametername = ($(value).text());
}
if (key == 1) {
param_Raiting = (strUser);
}
if (key == 2) {
para_Score =($(value).text());
}
});
parameters = {
"Name": parametername,
"Raiting": param_Raiting,
"Score": para_Score
}
paramarray.push(parameters);
if (islastchild === true) { // if row is last row add whole object in data
metrics = {
'Heading': Heading1,
'parameters': paramarray //parameter array that stores Paameter name and its weightage
}
var stringyfydata = JSON.stringify(metrics);
ObservationArray.push(stringyfydata); //pushing whole object in data1 array
paramarray = [];
metrics = {};
}
}
});
alert("ScoreCard=" + ObservationArray);
return ObservationArray;
}
The expected result :
ScoreCard={"Heading":"pawar","parameters":[{"Name":"nikita ","Raiting":"EE","Score":"0"},{"Name":"mayuri","Raiting":"ME","Score":"0"}]},{"Heading":" schoool","parameters":[{"Name":"sss","Raiting":"NI","Score":"0"}]}
I think you are always taking value from the same element in these lines
var e = document.getElementById("dropDownLevelChangetrue");
var strUser = e.options[e.selectedIndex].text;
Try to get them by name or something. getById always gets the first one in DOM node and ends
I want to modify SharePoint 2013 list column title in views with javascript. There is a code I found here at stackoverflow, but I want to reference the column with the display name / internal name, not with the column position.
(function () {
function preTaskFormRenderer(renderCtx) {
modifyHeaderData(renderCtx);
}
function modifyHeaderData(renderCtx)
{
var viewTitle = renderCtx.viewTitle;
var linkTitleField = renderCtx.ListSchema.Field[1];
linkTitleField.DisplayName = viewTitle + ':' + linkTitleField.DisplayName;
}
function registerRenderer()
{
var ctxForm = {};
ctxForm.Templates = {};
ctxForm.OnPreRender = preTaskFormRenderer;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
}
ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
})();
Example:
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPreRender: function(ctx) {
var field = getFieldByDisplayName(ctx,"Task Name");
if(field)
field.DisplayName = "Task Name:::";
}
});
});
function getFieldByDisplayName(ctx,name)
{
var result = ctx.ListSchema.Field.filter(function(f){return f.DisplayName == name;} ); //find field by display name
return result.length > 0 ? result[0] : null;
}
Result
I'm trying to convert javascript code from CRM 4.0 to CRM 2011.
I'm having problems with a picklist filter.
My function is on the onchange of the parent picklist. It works the first time but the second it erase everything from my child picklist.
This is the part where I suppose to reset the picklist
if(!oSubPicklist.originalPicklistValues)
{
oSubPicklist.originalPicklistValues = oSubPicklist.getOptions();
}
else
{
oSubPicklist.getOptions = oSubPicklist.originalPicklistValues;
oSubPicklist.setOptions = oSubPicklist.originalPicklistValues;
}
And this is the part where i remove all the option not related:
oTempArray is an array with the options that i want to keep. If a check the "oSubPicklist.getOptions.length" the value is the same that my original picklist.
for (var i=oSubPicklist.getOptions.length; i >= 0;i--)
{
if(oTempArray[i] != true)
{
Xrm.Page.getControl("new_product").removeOption(i);
}
}
Ideas?
Edit: I solved declaring a global var with the originalPickList in the onLoad event and:
oSubPicklist.clearOptions();
for (var i=0; i< oSubPicklist.originalPicklistValues.length; i++)
{
for (var j=0; j< oDesiredOptions.length; j++)
{
if (i == oDesiredOptions[j])
{oSubPicklist.addOption(oSubPicklist.originalPicklistValues[i]);}
}
}
Your code is not very clear to me: May be you could paste all your function code for better understanding but:
This is how you get the options from PickList in CRM 2011
var myOptionSet = Xrm.Page.ui.controls.get("new_product") //get Control
var optionsSet = myOptionSet .getAttribute().getOptions(); //get Options
preferredTimeOptionSet.clearOptions(); //Clear all options
//Create a new Option
var opt1 = new Option();
opt1.text = "one";
opt1.value = 1;
//Add Option
myOptionSet.addOption(opt1);
//Remove Option
myOptionSet.removeOption(1);
Good Example here
Here is another way to do Parent/Child picklists:
function dynamicDropdown(parent, child) {
filterPicklist(parent, child);
}
function parentListFilter(parent, id) {
var filter = "";
if (getParentCode(parent) != "") {
filter = getParentCode(parent);
} else {
// No [ ] match
}
return filter;
}
function filterPicklist(parent, child) {
var parentList = Xrm.Page.getAttribute(parent).getValue();
var childListControlAttrib = Xrm.Page.getAttribute(child);
var childListOptions = childListControlAttrib.getOptions();
var childListControl = Xrm.Page.getControl(child);
var codeToFilterListOn = parentListFilter(parent, parentList);
if (codeToFilterListOn != "") {
childListControl.clearOptions();
for (var optionIndex in childListOptions) {
var option = childListOptions[optionIndex];
// Ignore xx and check for Match
if (option.text.substring(0, 2) != "xx" && option.text.indexOf(codeToFilterListOn) > -1) {
childListControl.addOption(option);
}
}
} else {
// Didn't match, show all?
}
}
function getParentCode(parent) {
//Get Parent Code Dynamically from inside [ ]
var filter = "";
var parentValue = Xrm.Page.getAttribute(parent).getText();
if (parentValue && parentValue.indexOf("]") > -1) {
var parentCode = parentValue.substring(parentValue.indexOf("[") + 1, parentValue.indexOf("]"));
if (parentCode) {
filter = parentCode + " | ";
} else {}
}
return filter;
}
See more here: Parent/Child
I have 2 multi selects in a page, and I need to transfer some of the option in first into second, while mantaining the search capabilities.
The problem is, that when I use the search input, it restores the selects to their original options...
Here is the jquery search function:
jQuery.fn.filterByText = function(textbox) {
return this.each(function() {
var select = this;
var options = [];
$(select).find('option').each(function() {
options.push({value: $(this).val(), text: $(this).text()});
});
$(select).data('options', options);
$(textbox).bind('change keyup', function() {
var options = $(select).empty().data('options');
var search = $.trim($(this).val());
var regex = new RegExp(search,"gi");
$.each(options, function(i) {
var option = options[i];
if(option.text.match(regex) !== null) {
$(select).append(
$('<option>').text(option.text).val(option.value)
);
}
});
});
});
};
Here is the js fiddle : http://jsfiddle.net/C2XXR/ !
*I believe the problem lies in the options variable, but have no idea on how to solve it *
Thanks!
I have updated the fiddle. http://jsfiddle.net/C2XXR/2/
I have updated the code for right and left transfer. You have to change the option array itself got the filter, adding them in the dom will not work. In the changed code one issue is once we add from right to left or left to right it is getting added in the last position of the target select.
Please check and let me know if this is what you want.
Below is the main changed function. Later you can create a common function i suppose. Code can be optimized more.
$('[id^=\"btnRight\"]').click(function (e) {
var selected = $(this).parent().prev('select');
var target = $(this).parent().next('select');
target.find('option[value="999"]').remove()
var options = selected.data('options');
var selectedVal = selected.find('option:selected').val()
var tempOption = [];
$.each(options, function(i) {
var option = options[i];
if(option.value != selectedVal) {
tempOption.push(option);
}
});
var targetOptions = target.data('options');
targetOptions.push({value: selected.find('option:selected').val(), text: selected.find('option:selected').text()});
target.data('options', targetOptions);
selected.find('option:selected').remove().appendTo('#isselect_code');
selected.data('options', tempOption);
});
$('[id^=\"btnLeft\"]').click(function (e) {
var selected = $(this).parent().next('select');
var target = $(this).parent().prev('select');
var options = selected.data('options');
var selectedVal = selected.find('option:selected').val()
var tempOption = [];
$.each(options, function(i) {
var option = options[i];
if(option.value != selectedVal) {
tempOption.push(option);
}
});
if( tempOption.length == 0 )
{
// add 999 here
}
var targetOptions = target.data('options');
targetOptions.push({value: selected.find('option:selected').val(), text: selected.find('option:selected').text()});
target.data('options', targetOptions);
selected.find('option:selected').remove().appendTo('#canselect_code');;
selected.data('options', tempOption);
});
the problem with your code is that after you click btnRight or btnLeft your collection of options for each select is not updated, so try after click on each button to call your filterByText as the following :
$('[id^=\"btnRight\"]').click(function (e) {
$(this).parent().next('select').find('option[value="999"]').remove()
$(this).parent().prev('select').find('option:selected').remove().appendTo('#isselect_code');
$('#canselect_code').filterByText($('#textbox'), true);
$('#isselect_code').filterByText($('#textbox1'), true)
});
$('[id^=\"btnLeft\"]').click(function (e) {
$(this).parent().next('select').find('option:selected').remove().appendTo('#canselect_code');
$('#canselect_code').filterByText($('#textbox'), true);
$('#isselect_code').filterByText($('#textbox1'), true)
});
after changing the select box it must collect checked check box ids and the submit it
$("#action").change(function(){
if(($(this).val())!='0'){
var data = { 'req_ids[]' : []};
var doit = $("#action").val();
$(".checkboxes:checked").each(function(){
data['req_ids[]'].push($(this).attr('id'));
});
var size = Object.size(data['req_ids[]']);
if(size>0){
$.post("workplan-requests.php?action=update&do="+doit, data);
$("tr.checked").remove();
}
$("#action").val('0');
}
});
but when i select my action in select box by changing it,
it show this error:
TypeError: Object.size is not a function
var size = Object.size(data['req_ids[]']);
i know this error is because the java script run whole code at same time but how can i do this with out problem!?
it should be
var size = data['req_ids[]'].length;
Also try
$("#action").change(function () {
if (($(this).val()) != '0') {
var data = {};
data['req_ids[]'] = $(".checkboxes:checked").map(function () {
return this.id
}).get();
var size = data['req_ids[]'].length;
if (size > 0) {
var doit = $("#action").val();
$.post("workplan-requests.php?action=update&do=" + doit, data);
$("tr.checked").remove();
}
$("#action").val('0');
}
});