I have a function in JS which is triggered as event handler when user picks new option from dropdown.
function providerMarketingListOnChangeEventHandler() {
console.log("Provider marketing list option changed!");
// Get selected provider m. list option value
var selectedMarketingListValue = $(this).find("option:selected").text();
// Use XRM.Page API to set hidden attribute value to the value of the selected option
// Option 1 - this?
// Xrm.Page.getAttribute("new_marketinglist_provider").setValue(selectedMarketingListValue);
// Option 2 - or this?
// Xrm.Page.data.entity.attributes.get("new_marketinglist_provider").setValue(selectedMarketingListValue);
Xrm.Page.data.entity.save();
}
Dropdown is loaded as WebResource on CRM 2015 form. The entity for this form has field named "new_marketinglist_provider", but it has to be hidden on the form.
Now I am trying to save selected option text to this field, and save entity. I have two Xrm.Page API calls, but which one should I use? (Please see comments in function.)
try this :
Xrm.Page.getAttribute("new_marketinglist_provider").setValue(selectedMarketingListValue);
Xrm.Page.getAttribute("new_marketinglist_provider").setSubmitMode("always");
Related
I'm trying to programatically autofill my information on a form like this (Stripe's testing form) however I'm having trouble filling/selecting some of the fields.
For example, merely changing the Node's value attribute is not working for fields like the cardNumber field, and changing the selectedIndex attribute for the country does not have any effect.
Example:
selectedIndex = 40 from another index like 3 gives you Canada, which when done manually, will cause a Postal Code field to appear. However, I'm having trouble achieving this programmatically by just changing theselectedIndex
You can manually dispatch an event:
var select = document.getElementById('billingCountry')
select.dispatchEvent(new Event('change', { 'bubbles': true }))
I have a form in Angular 9, let's say it's for a language school. I want that the user can choose which language to study from a dropdown AND to add multiple languages by using "Add Language" button which adds another dropdown. The trick is that in the new dropdown, already selected languages shouldn't be available in the dropdown options. I followed the first answer to this question and all good:
How to remove the previously selected option from a drop-down menu in a table?
So, I have a array containing all available language names:
languageNames = [
{'name': "English"}, {'name': "Russian"}, {'name':"Spanish"}, {'name':"Czech"}, {'name':"Croatian"},
{'name':"Italian"}, {'name':"French"}, {'name':"German"}
];
I'm also watching what the user selected with:
#ViewChildren("selectLang") langSelects: QueryList<HTMLSelectElement>;
selectedLangs = new Set<string>();
Then I let the user choose a language from a dropdown:
<mat-select formControlName="name" (selectionChange)="selected()" #selectLang>
<ng-container *ngFor="let language of languageNames">
<mat-option *ngIf="selectLang.value === language.name || !isSelected(language.name)" [value]="language.name">
{{language.name}}
</mat-option>
</ng-container>
</mat-select>
on selection change I clear my selectedLangs set, the grab all the values from my form and add them back:
selected() {
this.selectedLangs.clear();
for (let c of this.languageForm.controls) {
const selectedVal = c.get('name').value;
if (selectedVal && selectedVal !== "undefined") this.selectedLangs.add(selectedVal);
}
}
and this is how I check should I show my option or not:
isSelected(lang: string) {
return this.selectedLangs.has(lang);
}
It works perfectly.
But, let's say a user in the future want's to edit his or her submission. When I fetch my data I add the selected languages to selectedLangs string Set using a forEach loop on my incoming data and selectedLangs.add(lang). The reason I want them in that string set is if a user adds a new dropdown for adding a new language, their previous selected languages shouldn't be available in the dropdown options. But here's the problem with this logic - in my edit form I only have empty dropdowns for each language selected when the user previously submitted the form because they are in the selectedLangs set.
These dropdowns should be populated with languages selected when submitting the form but they are empty
How to show previously selected values when I edit my form so the user can see which languages he selected but with the functionality that works just great when creating a form?
with JS you can set the selected value with .value
selectElement.value = "selected value"; The value needs to be the same as in the option value.
I have a form where I select a value in drop-down and submit it but when I try to access that form the value in the drop-down still remains selected, I want to deselect it on every new launch.
You can use the following to set the value of the dropdown to what you want.
document.querySelector('#idOfDropdown').value = desired_value;
// desired_value is the 'value' property of the option you want selected.
If the default option is written as
<option value=''>--select--</option>
...then, use this:
document.querySelector('#idOfDropdown').value = '';
I'm assuming that this line will be best placed at the end of the function that gets called when you submit the Form.
I want to use 2 fields as filter to open a url.
How am I going to code this in javascript.
if model=pbga and model=stm
use matrix2_add.php
otherwise
use matrix_add.php
when this model (e.g. pbga) is chosen under the dropdown list, it will automatically go to this url page matrix2_add.php. If a different model is chosen, it will stay on the same page matrix_add.php.
These models are in this dropdown list: >>PBGA >>KRTM >>LST >>MRTO >>HRMS.
if(model == 'pbga')
window.open("matrix2_add.php"); // if condition is true
window.open("matrix_add.php"); // else part
I'm using Scripaculous' in place collection editor to present the user a with list of customers to assign to a contact dynamically. I am passing a value parameter as detailed in the documentation so when the select is generated it will auto-select the current associated customer (if there is not one already the default is provided.)
This works well except when the user clicks on the 'edit me' field a second time the original value is selected, not the customer that was selected most recently. This is because the original call to InPlaceCollectionEditor is unchanged. My question is whether there is any way to update the autoselect value without dynamically updating the entire scriptaculous call (this would mean selecting all the customers again via ajax, which is possible but not ideal.)
Here is the code:
<div id="editme">Test 1</div>
<script type="text/javascript">
new Ajax.InPlaceCollectionEditor(
'editme',
'/usercustomer/editCustomer/id/811',
{ collection: [['192981', "Test 1"],['192893', "Test 2"],['192894', "Test 3"] ... ],
ajaxOptions: {method: 'get'}
, value: 192893 } // specifying the value parameter auto selects object id 192893
);
</script>
Is this a limitation of InPlaceCollectionEditor or is there some other way around this?
Pass a variable instead of the hardcoded number as 'value'. Set that variable to the initial or selected value right before making the call.