Need a Jquery function to detect input loses focus

Thomas_StickelThomas_Stickel Customer IT Monkey ✭
Seems that I am wanting to detect when an input box in Asset , loses focus  then add to the model.

I am not sure that the name is unique - I cannot add an ID to it.    
CustomSpace --   HardwareAsset.js   -->   
columnFieldList: [
{ DataType: "UserPicker", PropertyDisplayName: "PrimaryUser", PropertyName: "Target_HardwareAssetHasPrimaryUser", Disabled: false },
{ DataType: "ObjectPicker", PropertyDisplayName: "CatalogItem", PropertyName: "Target_HardwareAssetHasCatalogItem", ClassId: "98FBECC7-F76A-DCD6-7B17-62CEE34E38DE", Disabled: false }
],

Then in the  custom.js

app.custom.formTasks.add('HardwareAsset', null, function(formObj, viewModel) {
console.log('loaded function');

// that works above 

but I cannot get this to hit 
$("input[name='Target_HardwareAssetHasCatalogItem']").blur(function() {
      console.log('Triggered');
      // viewModel.Model = 'Model S';
// })


Best Answer

  • Geoff_RossGeoff_Ross Cireson Consultant Super IT Monkey ✭✭✭✭✭
    Accepted Answer
    Ok, timing issues... Try

    app.custom.formTasks.add('HardwareAsset', null, function(formObj, viewModel) {
    	$(document).ready(function () {  /// This is the function that waits for page to load
    		pageForm.viewModel.Target_HardwareAssetHasCatalogItem.bind("change", function (){
    			//console.log("changed");
    			var baseurl = location.origin
    			var catId = pageForm.viewModel.Target_HardwareAssetHasCatalogItem.BaseId;
    			
    			$.ajax({
    				url: 'api call to get model' + catId,
    				type: "GET",
    				dataType: "json",
    				contentType: 'application/json; charset=UTF-8',
    				success: function (Cat) {
    					pageForm.viewModel.set("Manufacturer",Cat[0].Man)
    					pageForm.viewModel.set("Model",Cat[0].Mod)
    				}	
    			});
    		});
    	});
    });
    

Answers

  • Geoff_RossGeoff_Ross Cireson Consultant Super IT Monkey ✭✭✭✭✭
    edited June 4
    Hi @Thomas_Stickel

    I see what you are trying to do there, nice idea. I don't know about how to trigger on the lose of focus but you can bind to the change event. This is how I did it.
    pageForm.viewModel.Target_HardwareAssetHasCatalogItem.bind("change", function (){
    	//console.log("changed");
    	var baseurl = location.origin
    	var catId = pageForm.viewModel.Target_HardwareAssetHasCatalogItem.BaseId;
    	
    	$.ajax({
    		url: 'api call to get model' + catId,
    		type: "GET",
    		dataType: "json",
    		contentType: 'application/json; charset=UTF-8',
    		success: function (Cat) {
    			pageForm.viewModel.set("Manufacturer",Cat[0].Man)
    			pageForm.viewModel.set("Model",Cat[0].Mod)
    		}	
    	});
    });

    Geoff
  • Thomas_StickelThomas_Stickel Customer IT Monkey ✭
    TypeError: pageForm.viewModel.Target_HardwareAssetHasCatalogItem is undefined
  • Geoff_RossGeoff_Ross Cireson Consultant Super IT Monkey ✭✭✭✭✭
    Did you wrap my code into your task code? The error you are getting is the code executing before the viewModel is properly loaded.
  • Thomas_StickelThomas_Stickel Customer IT Monkey ✭
    app.custom.formTasks.add('HardwareAsset', null, function(formObj, viewModel) {
            console.log('loaded function');
            viewModel.Manufacturer = 'Make it Wierd';


            pageForm.viewModel.Target_HardwareAssetHasCatalogItem.bind("change", function (){    
                var baseurl = location.origin;    
                var catId = pageForm.viewModel.Target_HardwareAssetHasCatalogItem.BaseId; 

                console.log(baseurl);
                console.log(catId);
            });
        
    });
  • Thomas_StickelThomas_Stickel Customer IT Monkey ✭
    Thoughts??
  • Thomas_StickelThomas_Stickel Customer IT Monkey ✭
    i see that there is a "boundReady" for service and incident requests,  but not for HardwareAsset

    app.custom.formTasks.add('ServiceRequest', null, function(formObj, viewModel) {
        formObj.boundReady(function() {
            if (viewModel.Project.Name == 'Personnel Move') {
                fn_ShowTab("MOVE", formObj)
            } else {
                fn_HideTab("MOVE", formObj)
            }
        });
    });
  • Thomas_StickelThomas_Stickel Customer IT Monkey ✭
    Thoughts on this?

  • Geoff_RossGeoff_Ross Cireson Consultant Super IT Monkey ✭✭✭✭✭
    Accepted Answer
    Ok, timing issues... Try

    app.custom.formTasks.add('HardwareAsset', null, function(formObj, viewModel) {
    	$(document).ready(function () {  /// This is the function that waits for page to load
    		pageForm.viewModel.Target_HardwareAssetHasCatalogItem.bind("change", function (){
    			//console.log("changed");
    			var baseurl = location.origin
    			var catId = pageForm.viewModel.Target_HardwareAssetHasCatalogItem.BaseId;
    			
    			$.ajax({
    				url: 'api call to get model' + catId,
    				type: "GET",
    				dataType: "json",
    				contentType: 'application/json; charset=UTF-8',
    				success: function (Cat) {
    					pageForm.viewModel.set("Manufacturer",Cat[0].Man)
    					pageForm.viewModel.set("Model",Cat[0].Mod)
    				}	
    			});
    		});
    	});
    });
    
Sign In or Register to comment.