Have any questions? info@awareindevelopers.com; support@customaware.com

Place Cursor in 1st Field on a Form – Slick Version

This solution is compliments of John Talbot who is the steely eyed missile man. Excellent…

  1. Place the Code below in a custom JS file and place the file in your webapps/AwareCustom/JS folder.
  2. In the Init Script of a VP content panel call the set up function. It doesn’t matter which panel, we’re just using it as a place to execute the code before forms are being rendered.setupDefaultFocus()
  3. Kick your feet up, drink some vodka …

    AwareIM Version: v7

    Dependencies: 

    Where: Advanced Script - Init of VP Content Panel

    Script: 

    function setupDefaultFocus() {
       
       AwareApp_FormParser.prototype.setFocus = function (sectionName) {
          if (this.m_fields) {
             var firstTabIdx = null,
             focusSet = false;
             for (var i = 0, len = this.m_fields.length; i < len; ++i) {
                var f = this.m_fields[i];
                var tabIndex = f.getTabIndex();
                if (tabIndex && tabIndex == "1") {
                   firstTabIdx = f;
                   if ((!sectionName || sectionName == f.getSectionName()) && f.setFocus())
                      focusSet = true;
                   break;
                }
             }
             if (!focusSet) {
                for (var i = 0, len = this.m_fields.length; i < len; ++i) {
                   var f = this.m_fields[i];
                   if (f != firstTabIdx && (!sectionName || sectionName == f.getSectionName()) && f.setFocus())
                      break;
                }
             }
          }
       }   
       
    }

     

    Posted in