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 default value to prompt preset.
Browse files Browse the repository at this point in the history
Fixes #7046
  • Loading branch information
devversion committed Mar 21, 2016
1 parent 08bf4f9 commit f4c9822
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/components/dialog/demoBasicUsage/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ 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')
.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 @@ -385,6 +385,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#defaultValue(string) - Sets the default 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 @@ -503,7 +504,7 @@ function MdDialogProvider($$interimElementProvider) {
options: advancedDialogOptions
})
.addPreset('prompt', {
methods: ['title', 'htmlContent', 'textContent', 'content', 'placeholder', 'ariaLabel',
methods: ['title', 'htmlContent', 'textContent', 'defaultValue', 'content', 'placeholder', 'ariaLabel',
'ok', 'cancel', 'theme', 'css'],
options: advancedDialogOptions
});
Expand All @@ -521,7 +522,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 @@ -536,8 +538,14 @@ function MdDialogProvider($$interimElementProvider) {
'</md-dialog>'
].join('').replace(/\s\s+/g, ''),
controller: function mdDialogCtrl() {
var isPrompt = this.$type == 'prompt';

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

this.hide = function() {
$mdDialog.hide(this.$type === 'prompt' ? this.result : true);
$mdDialog.hide(isPrompt ? this.result : true);
};
this.abort = function() {
$mdDialog.cancel();
Expand Down
4 changes: 3 additions & 1 deletion src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ describe('$mdDialog', function() {
.title('Title')
.textContent('Hello world')
.placeholder('placeholder text')
.defaultValue('default value')
.theme('some-theme')
.css('someClass anotherClass')
.ok('Next')
Expand All @@ -576,6 +577,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('default value');
expect(buttons.length).toBe(2);
expect(buttons.eq(0).text()).toBe('Next');
expect(theme).toBe('some-theme');
Expand Down Expand Up @@ -606,7 +608,7 @@ describe('$mdDialog', function() {
.parent(parent)
.textContent('Hello world')
.placeholder('placeholder text')
)
);

runAnimation(parent.find('md-dialog'));

Expand Down

0 comments on commit f4c9822

Please sign in to comment.