2

.NET is removing the name attribute from the form element I've defined in my master page:

<form
   name="aspnetForm"
   runat="server"
   onsubmit="if (typeof(_spFormOnSubmitWrapper) != 'undefined') {return _spFormOnSubmitWrapper();} else {return true;}"
   ng-model-options="{updateOn: 'default blur','debounce':{'default':250,'blur':0}}">

which gets rendered as:

<form
   method="post"
   action="...the current url..."
   onsubmit="javascript:return WebForm_OnSubmit();"
   id="aspnetForm"
   ng-model-options="{updateOn:'default blur','debounce':{'default':250,'blur':0}}"
   class="ng-pristine ng-invalid ng-invalid-required ng-valid-date"> == $0

From W3 and Microsoft, it seems that the name attribute is formally depreciated in XHTML 1.0 and not allowed in 1.1, and we should use the id attribute instead. However, AngularJS uses the name attribute to publish the form on the current scope. I want to check the validity of the form using AngularJS with ng-disabled="!aspnetForm.$valid" but don't see how to make $scope aware of the form. I've tried a few variations of this suggested code in my controller without success. I've also tried setting the clientidmode to static but that doesn't seem to affect the name tag.

Community
  • 1
  • 1
Aron Foster
  • 558
  • 7
  • 18

1 Answers1

1

The scope name of the form can also be set using the attribute ng-form='aspnetForm'. You can see that in the source code for where it sets the name.

Matthew Green
  • 10,161
  • 4
  • 36
  • 54
  • Now I'm getting an error because I have ``, which has this problem: http://stackoverflow.com/a/20893935/2596509. Thoughts? – Aron Foster Apr 10 '17 at 16:00
  • Any reason using a div like the answer mentions wouldn't work? – Matthew Green Apr 10 '17 at 16:10
  • I need the `
    ` submit functionality.
    – Aron Foster Apr 10 '17 at 16:49
  • And if I do a `
    ` I get a whole bunch of errors, currently "control ... of type 'ScriptManager' must be placed inside a form tag". I'm going to unaccept your answer temporarily until we can figure out how to get Angular recognizing my form tag.
    – Aron Foster Apr 10 '17 at 16:57
  • Then you might be at a point where you need to throw something out. You could use Angular's form submit option instead or use HTML5 instead of XHTML 1.1 or use .NET form validation instead of Angular. As for the actual question of how to get the form on the scope, this answer is correct and unfortunately is the only other option I can see that will do this for you. – Matthew Green Apr 10 '17 at 17:02
  • Matthew, I appreciate your help, but I don't agree that this is a correct answer to my question. If a XHTML 1.1 compliant form element cannot be referenced by Angular then I think this question should remain unanswered. – Aron Foster Apr 10 '17 at 17:17