Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 2090136

Browse files
vojtajinaIgorMinar
authored andcommitted
docs(ng:submit): update docs example to not add empty items
1 parent c9f2b1e commit 2090136

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/directives.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,16 @@ angularDirective("ng:click", function(expression, element){
500500
this.list = [];
501501
this.text = 'hello';
502502
this.submit = function() {
503-
this.list.push(this.text);
504-
this.text = '';
503+
if (this.text) {
504+
this.list.push(this.text);
505+
this.text = '';
506+
}
505507
};
506508
}
507509
</script>
508510
<form ng:submit="submit()" ng:controller="Ctrl">
509511
Enter text and hit enter:
510-
<input type="text" ng:model="text"/>
512+
<input type="text" ng:model="text" name="text" />
511513
<input type="submit" id="submit" value="Submit" />
512514
<pre>list={{list}}</pre>
513515
</form>
@@ -517,6 +519,13 @@ angularDirective("ng:click", function(expression, element){
517519
expect(binding('list')).toBe('list=[]');
518520
element('.doc-example-live #submit').click();
519521
expect(binding('list')).toBe('list=["hello"]');
522+
expect(input('text').val()).toBe('');
523+
});
524+
it('should ignore empty strings', function() {
525+
expect(binding('list')).toBe('list=[]');
526+
element('.doc-example-live #submit').click();
527+
element('.doc-example-live #submit').click();
528+
expect(binding('list')).toBe('list=["hello"]');
520529
});
521530
</doc:scenario>
522531
</doc:example>

0 commit comments

Comments
 (0)