Skip to content

Commit

Permalink
Build 1.1 Added TagInput.Reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
divyamamgai committed Jul 12, 2016
1 parent 50ae806 commit 390f345
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
45 changes: 23 additions & 22 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions TagInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@
}
return false;
},
/**
* @return {boolean}
*/
RemoveTag: function ($tag, index) {
// We subtract 1 because label element takes up 1 index.
index = index || ($tag.index() - 1);
var Text = TagArray[index].Text;
TagArray.splice(index, 1);
$tag.remove();
PublicPrototype.UpdateValue();
$Element.trigger('TagInput:RemoveTag', [TagArray, Text]);
var TagIndex = index || ($tag.index() - 1),
TagObject = TagArray[TagIndex];
if (TagObject !== undefined) {
var Text = TagObject.Text;
TagObject.$Tag.remove();
TagArray.splice(TagIndex, 1);
PublicPrototype.UpdateValue();
$Element.trigger('TagInput:RemoveTag', [TagArray, Text]);
return true;
}
return false;
},
GetArray: function () {
return TagArray;
Expand Down Expand Up @@ -125,6 +133,17 @@
$Element.attr('disabled', 'disabled');
return Name;
},
Reset: function () {
var TagCount = TagArray.length;
for (var TagIndex = 0; TagIndex < TagCount; TagIndex++) {
TagArray[TagIndex].$Tag.remove();
}
TagArray = [];
$Element.val('');
$TagInputText.val('');
$TagInputLabel.removeClass(Options.LabelAnimationClass);
return PublicPrototype;
},
Private: undefined
},
PrivatePrototype = {
Expand Down
2 changes: 1 addition & 1 deletion TagInput.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ <h5>CSS Code</h5>
[, <code>number</code> ]
</td>
<td>
<code>null</code>
<code>boolean</code>
</td>
<td>
Removes the <b>Tag</b> specified by the jQuery object of that <b>Tag</b>. If the index
of the <b>Tag</b> in the <b>TagArray</b> is available it can be passed as the second
parameter, in that case it is not calculated again.
parameter, in that case it is not calculated using the element provided. It returns
<code>true</code> on success and <code>false</code> on failure.
</td>
</tr>
<tr>
Expand Down Expand Up @@ -307,6 +308,18 @@ <h5>CSS Code</h5>
<code>onSubmit</code> event. It returns the name attribute given to hidden inputs.
</td>
</tr>
<tr>
<td>Reset</td>
<td>
<code>null</code>
</td>
<td>
<code>TagInput</code>
</td>
<td>
Clears the <b>TagInput</b> element completely for the next time input.
</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -393,8 +406,10 @@ <h4>
$('form').on('submit', function (event) {
event.stopPropagation();
event.preventDefault();
var Name = $.data($TagInputElement[0], 'TagInput').ConvertToHiddenInput();
$TagInputStatus.html('<b>Submitted ::</b> Converted <code>$TagInput</code> into array of hidden input (<code>name="' + Name + '"</code>) and disabled original input element.');
var KeywordsTagInput = $.data($TagInputElement[0], 'TagInput'),
Name = KeywordsTagInput.ConvertToHiddenInput();
KeywordsTagInput.Reset();
$TagInputStatus.html('<b>Submitted ::</b> Converted <code>$TagInput</code> into array of hidden input (<code>name="' + Name + '"</code>) and disabled original input element. Called <code>TagInput.Reset()</code> to clear the field.');
});
});
})(jQuery);
Expand Down

0 comments on commit 390f345

Please sign in to comment.