@@ -790,6 +790,30 @@ angular
790790 return - 1 ;
791791 }
792792
793+ /** From a javascript plain form object, find its equivalent Angular object
794+ * @param object formObj
795+ * @param object self
796+ * @return object angularParentForm or null
797+ */
798+ function findAngularParentFormInScope ( formObj , self ) {
799+ var formName = ( ! ! formObj ) ? formObj . getAttribute ( "name" ) : null ;
800+
801+ if ( ! ! formObj && ! ! formName ) {
802+ parentForm = ( ! ! _globalOptions && ! ! _globalOptions . controllerAs && formName . indexOf ( '.' ) >= 0 )
803+ ? objectFindById ( self . scope , formName , '.' )
804+ : self . scope [ formName ] ;
805+
806+ if ( ! ! parentForm ) {
807+ if ( typeof parentForm . $name === "undefined" ) {
808+ parentForm . $name = formName ; // make sure it has a $name, since we use that variable later on
809+ }
810+ return parentForm ;
811+ }
812+ }
813+
814+ return null ;
815+ }
816+
793817 /** Get the element's parent Angular form (if found)
794818 * @param string: element input name
795819 * @param object self
@@ -811,28 +835,22 @@ angular
811835
812836 for ( var i = 0 ; i < forms . length ; i ++ ) {
813837 var form = forms [ i ] . form ;
814- var formName = ( ! ! form ) ? form . getAttribute ( "name" ) : null ;
815-
816- if ( ! ! form && ! ! formName ) {
817- parentForm = ( ! ! _globalOptions && ! ! _globalOptions . controllerAs && formName . indexOf ( '.' ) >= 0 )
818- ? objectFindById ( self . scope , formName , '.' )
819- : self . scope [ formName ] ;
820-
821- if ( ! ! parentForm ) {
822- if ( typeof parentForm . $name === "undefined" ) {
823- parentForm . $name = formName ; // make sure it has a $name, since we use that variable later on
824- }
825- return parentForm ;
826- }
838+ var angularParentForm = findAngularParentFormInScope ( form , self ) ;
839+ if ( ! ! angularParentForm ) {
840+ return angularParentForm ;
827841 }
828842 }
829843
830- // if we haven't found a form yet, then we have a special angular element, let's try with .closest (this might not work with older browser)
844+ // if we haven't found a form yet, then we have a special angular element, let's try with .closest
831845 if ( ! form ) {
832- var element = document . querySelector ( '[name="' + elmName + '"]' ) ;
833- if ( element ) {
834- form = element . closest ( "form" ) ;
846+ var element = document . querySelector ( '[name="' + elmName + '"]' ) ;
847+ if ( ! ! element ) {
848+ var form = element . closest ( "form" ) ;
849+ var angularParentForm = findAngularParentFormInScope ( form , self ) ;
850+ if ( ! ! angularParentForm ) {
851+ return angularParentForm ;
835852 }
853+ }
836854 }
837855
838856 // falling here with a form name but without a form object found in the scope is often due to isolate scope
0 commit comments