Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textbox not updating when an option is unselected. #37

Closed
moussa1 opened this issue Apr 30, 2021 · 5 comments
Closed

Textbox not updating when an option is unselected. #37

moussa1 opened this issue Apr 30, 2021 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@moussa1
Copy link

moussa1 commented Apr 30, 2021

If I select 3 options and close, the label shows "3 options selected", however when I unselect an option, the label still shows "3 options selected".

@sa-si-dev
Copy link
Owner

@moussa1 please share the code you are using to initialize dropdown.

@moussa1
Copy link
Author

moussa1 commented May 1, 2021

	<script type="text/javascript">

		var types;
		var Main = [];
		var virtualSelectVar;

		$(document).ready(function() {			
			$(document).on('click', '#box3', function() { GetRegionDetails();});
	
			function GetRegionDetails() {
				parent.Xrm.WebApi.retrieveMultipleRecords("mcs_region", "?$select=mcs_name,mcs_inpanicmode,mcs_regionid").then(
					function success(result) {
						if (result.entities.length > 0) {
							$( "#panicdetails" ).show( "fade" );
							$( ".quotes" ).hide( "fade" );
								
							for (var i = 0; i < result.entities.length; i++) {
													
								var regionid = result.entities[i].mcs_regionid;
								var inpanicmode = result.entities[i].mcs_inpanicmode;
								var name = result.entities[i].mcs_name;
								
								var stringBuilder = "<div class='panicContainer'><h3 class='labelH3'>" + name + "</h3>";
								
								//add disaster types dropdownlist
								if (types.length > 0)
								{
									stringBuilder += '<div class="panicSelectContainer" id="select_' + regionid + '"></div>';
								}
								
								for (var j = 0; j < types.length; j++) {
																
									var option = {};
									option.label = types[j].mcs_name;
									option.value = types[j].mcs_disastertypesid;
									Main.push(option);
								}
								
								stringBuilder += "<div class='panicSwitchContainer'><div class='switch' id='switch'>"+'<input class="cmn-toggle cmn-toggle-round" type="checkbox" id="togBtn_' + regionid + '" data-value="' + i + '" />';
								stringBuilder += '<label for="togBtn_' + regionid + '"></label></div>';

								$('#panicdetails').append(stringBuilder);
								
								$("#togBtn_" + regionid).prop("checked", inpanicmode);
								
								var select_selector = '#select_' + regionid;
								
								virtualSelectVar = VirtualSelect.init({
								  ele: select_selector,
								  options: Main,
								  search: true,
								  multiple: true
								});	
								
								
								var chkbox = "#togBtn_" + regionid;
								
								$(chkbox).change(function() {
									if(this.checked) {
										var returnVal = confirm("Are you sure you want to turn panic mode ON?");
										$(this).prop("checked", returnVal);
										
										if (returnVal)
										{
											$("#select_" + ($(this).attr('id')).substr(($(this).attr('id')).lastIndexOf("_")+1)).show();
											
										}
									}
									else{
										$("#select_" + ($(this).attr('id')).substr(($(this).attr('id')).lastIndexOf("_")+1)).hide();
									}
								});
								
								if (!inpanicmode)
								{
									$(select_selector).hide();
								}
							}
						}
					},
					function (error) {
						console.log(error.message);
					}
				);
			}

			function GetDisasterTypes() {
					parent.Xrm.WebApi.retrieveMultipleRecords("mcs_disastertype", "?$select=mcs_name,mcs_disastertypeid").then(
						function success(typesresult) {
							types = typesresult.entities;
							console.log("FIRST " + typesresult);
						},
						function (error) {
							console.log(error.message);
							// handle error conditions
						}
					);
			}
		
		GetDisasterTypes();
		
		});

	</script>

@sa-si-dev
Copy link
Owner

@moussa1 please check that does multiple dropdown options has same value.

@moussa1
Copy link
Author

moussa1 commented May 1, 2021

Yes multiple dropdown options will have same value... how can i fix this issue pls?

@moussa1
Copy link
Author

moussa1 commented May 1, 2021

never mind i got it working. thank you

@sa-si-dev sa-si-dev self-assigned this May 2, 2021
@sa-si-dev sa-si-dev added the question Further information is requested label May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants