Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(dialog): add initial value option to prompt preset.
Browse files Browse the repository at this point in the history
Fixes #7046

Closes #7090
  • Loading branch information
devversion authored and ThomasBurleson committed Jun 3, 2016
1 parent c6c5d48 commit b49ebcf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 8 additions & 7 deletions src/components/dialog/demoBasicUsage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ angular.module('dialogDemo1', ['ngMaterial'])
$scope.showPrompt = function(ev) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.prompt()
.title('What would you name your dog?')
.textContent('Bowser is a common name.')
.placeholder('dog name')
.ariaLabel('Dog name')
.targetEvent(ev)
.ok('Okay!')
.cancel('I\'m a cat person');
.title('What would you name your dog?')
.textContent('Bowser is a common name.')
.placeholder('Dog name')
.ariaLabel('Dog name')
.initialValue('Buddy')
.targetEvent(ev)
.ok('Okay!')
.cancel('I\'m a cat person');

$mdDialog.show(confirm).then(function(result) {
$scope.status = 'You decided to name your dog ' + result + '.';
Expand Down
14 changes: 11 additions & 3 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
* - $mdDialogPreset#htmlContent(string) - Sets the prompt message as HTML. Requires ngSanitize
* module to be loaded. HTML is not run through Angular's compiler.
* - $mdDialogPreset#placeholder(string) - Sets the placeholder text for the input.
* - $mdDialogPreset#initialValue(string) - Sets the initial value for the prompt input.
* - $mdDialogPreset#ok(string) - Sets the prompt "Okay" button text.
* - $mdDialogPreset#cancel(string) - Sets the prompt "Cancel" button text.
* - $mdDialogPreset#theme(string) - Sets the theme of the prompt dialog.
Expand Down Expand Up @@ -544,7 +545,7 @@ function MdDialogProvider($$interimElementProvider) {
options: advancedDialogOptions
})
.addPreset('prompt', {
methods: ['title', 'htmlContent', 'textContent', 'content', 'placeholder', 'ariaLabel',
methods: ['title', 'htmlContent', 'textContent', 'initialValue', 'content', 'placeholder', 'ariaLabel',
'ok', 'cancel', 'theme', 'css'],
options: advancedDialogOptions
});
Expand All @@ -562,7 +563,8 @@ function MdDialogProvider($$interimElementProvider) {
' <p>{{::dialog.mdTextContent}}</p>',
' </div>',
' <md-input-container md-no-float ng-if="::dialog.$type == \'prompt\'" class="md-prompt-input-container">',
' <input ng-keypress="dialog.keypress($event)" md-autofocus ng-model="dialog.result" placeholder="{{::dialog.placeholder}}">',
' <input ng-keypress="dialog.keypress($event)" md-autofocus ng-model="dialog.result" ' +
' placeholder="{{::dialog.placeholder}}">',
' </md-input-container>',
' </md-dialog-content>',
' <md-dialog-actions>',
Expand All @@ -577,8 +579,14 @@ function MdDialogProvider($$interimElementProvider) {
'</md-dialog>'
].join('').replace(/\s\s+/g, ''),
controller: function mdDialogCtrl() {
var isPrompt = this.$type == 'prompt';

if (isPrompt && this.initialValue) {
this.result = this.initialValue;
}

this.hide = function() {
$mdDialog.hide(this.$type === 'prompt' ? this.result : true);
$mdDialog.hide(isPrompt ? this.result : true);
};
this.abort = function() {
$mdDialog.cancel();
Expand Down
2 changes: 2 additions & 0 deletions src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ describe('$mdDialog', function() {
.title('Title')
.textContent('Hello world')
.placeholder('placeholder text')
.initialValue('initial value')
.theme('some-theme')
.css('someClass anotherClass')
.ok('Next')
Expand All @@ -604,6 +605,7 @@ describe('$mdDialog', function() {
expect(title.text()).toBe('Title');
expect(contentBody.textContent).toBe('Hello world');
expect(inputElement[0].placeholder).toBe('placeholder text');
expect(inputElement.val()).toBe('initial value');
expect(buttons.length).toBe(2);
expect(buttons.eq(0).text()).toBe('Next');
expect(theme).toBe('some-theme');
Expand Down

0 comments on commit b49ebcf

Please sign in to comment.