Skip to content

Commit

Permalink
Add setPlaceholderNumberType public method
Browse files Browse the repository at this point in the history
  • Loading branch information
cedk committed Sep 25, 2017
1 parent 4add25a commit 8a0e12c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ Insert a number, and update the selected flag accordingly. _Note that if `format
$("#phone").intlTelInput("setNumber", "+447733123456");
```

**setPlaceholderNumberType**
Change the placeholderNumberType option.
```js
$("#phone").intlTelInput("setPlaceholderNumberType", "FIXED_LINE");
```


## Static Methods

Expand Down
5 changes: 5 additions & 0 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@
if (flagChanged) {
this._triggerCountryChange();
}
},
// set the placeholder number typ
setPlaceholderNumberType: function(type) {
this.options.placeholderNumberType = type;
this._updatePlaceholder();
}
};
// using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

<script src="src/spec/tests/methods/setNumber.js"></script>

<script src="src/spec/tests/methods/setPlaceholderNumberType.js"></script>

<script src="src/spec/tests/options/allowDropdown.js"></script>

<script src="src/spec/tests/options/autoHideDialCode.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions src/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,12 @@ Plugin.prototype = {
if (flagChanged) {
this._triggerCountryChange();
}
},

// set the placeholder number typ
setPlaceholderNumberType: function(type) {
this.options.placeholderNumberType = type;
this._updatePlaceholder();
}

};
Expand Down
28 changes: 28 additions & 0 deletions src/spec/tests/methods/setPlaceholderNumberType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";

describe("setPlaceholderNumberType: init vanilla plugin and call setPlaceholderNumberType with 'FIXED_LINE'", function() {

beforeEach(function() {
intlSetup(true);
input = $("<input>");
input.intlTelInput({
initialCountry: "gb"
});
});

afterEach(function() {
input.intlTelInput("destroy'");
input = null;
});

it("sets the placeholder to fixed line", function() {
input.intlTelInput("setPlaceholderNumberType", "FIXED_LINE");
expect(input.attr("placeholder")).toEqual("0121 234 5678");
});

it("sets the placeholder to mobile", function() {
input.intlTelInput("setPlaceholderNumberType", "MOBILE");
expect(input.attr("placeholder")).toEqual("07400 123456");
});

});

0 comments on commit 8a0e12c

Please sign in to comment.