locked
Form field value not updated until field loses focus RRS feed

  • Question

  • I have a button on the form that executes a javascript trying to retrieve form field values. But if the control containing the value is still in focus the old value will be returned by the attributes getValue() function.

    This results in the wrong value being used. Now the users are told to commit each value using the enter-key which is easy to forget.

    Does anyone know how to "commit" the edited value using javascript? I have tried to move the focus to another control but this does not solve the issue.

    Wednesday, November 13, 2013 11:53 AM

Answers

  • It turned out that saving the form caused some other problems as the form is validated and saved. I really just want to act on the current form values, not save them. I came up with a solution that will give access to the newly edited value:

    setTimeout(

    function() {

            alert(Xrm.Page.getAttribute(

    'dit_accountnotemultirow').getValue());

        }, 1);

    The timeout will let focus move to the button before reading the value of the recently edited field.

    • Marked as answer by Per Lindblom Thursday, November 21, 2013 3:40 PM
    Thursday, November 21, 2013 3:40 PM

All replies

  • Have you tried forcing a form save via JS and then retrieving your form field values?

    The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.

    • Marked as answer by Per Lindblom Wednesday, November 13, 2013 2:00 PM
    • Unmarked as answer by Per Lindblom Thursday, November 21, 2013 3:32 PM
    Wednesday, November 13, 2013 1:47 PM
  • Thanks! Saving the form solvs the problem!

    Wednesday, November 13, 2013 2:00 PM
  • Cool, glad that worked for you. :)

    The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.

    Thursday, November 14, 2013 2:35 AM
  • It turned out that saving the form caused some other problems as the form is validated and saved. I really just want to act on the current form values, not save them. I came up with a solution that will give access to the newly edited value:

    setTimeout(

    function() {

            alert(Xrm.Page.getAttribute(

    'dit_accountnotemultirow').getValue());

        }, 1);

    The timeout will let focus move to the button before reading the value of the recently edited field.

    • Marked as answer by Per Lindblom Thursday, November 21, 2013 3:40 PM
    Thursday, November 21, 2013 3:40 PM
  • Another solution.

    Not a supported way but who cares.

    function getFreshValue(fieldName){
    	var id = fieldName + '_i';
    	var inputElement = document.getElementById(id);
    	if(inputElement !== null){ //At the moment when you focus the field first, the input element get generated.(at least on CRM 2013)
    		return inputElement.value;	
    	}else{
    		return Xrm.Page.getAttribute(fieldName).getValue(); //The value is not modified if the input element doesn't exist.
    	}
    }

    tested on CRM 2013.


    Taichi,Sato



    • Edited by dora_san Wednesday, February 26, 2014 5:16 AM
    Wednesday, February 26, 2014 4:43 AM
  • Hi,

    The above function is not working for Date fields.

    Thursday, February 5, 2015 6:18 AM