Skip to content

Commit

Permalink
fix(popup): only override prompt input if template includes HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygovier committed Aug 8, 2014
1 parent c336e8e commit 044fac4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/angular/service/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,13 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume
function showPrompt(opts) {
var scope = $rootScope.$new(true);
scope.data = {};
var text = '';
if(opts.template && /<[a-z][\s\S]*>/i.test(opts.template) === false){
text = '<span>'+opts.template+'</span>';
delete opts.template;
}
return showPopup( extend({
template: '<input ng-model="data.response" type="' + (opts.inputType || 'text') +
template: text+'<input ng-model="data.response" type="' + (opts.inputType || 'text') +
'" placeholder="' + (opts.inputPlaceholder || '') + '">',
scope: scope,
buttons: [{
Expand Down
11 changes: 11 additions & 0 deletions test/unit/angular/service/popup.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,16 @@ describe('$ionicPopup service', function() {
$timeout.flush();
expect($ionicBackdrop.release).toHaveBeenCalled();
}));
it('template should only overwrite prompt input if it includes html', inject(function($timeout) {
spyOn($ionicPopup, '_createPopup');
$ionicPopup.prompt({template: "Tacos!"});
params = $ionicPopup._createPopup.mostRecentCall.args;
expect(params[0].template.indexOf('<span>Tacos!</span>')).toEqual(0);
expect(params[0].template.indexOf('<input')).toBeGreaterThan(6);

$ionicPopup.prompt({template: '<input type="email" />'});
params = $ionicPopup._createPopup.mostRecentCall.args;
expect(params[0].template.indexOf('<input type="email" />')).toEqual(0);
}));
});
});

0 comments on commit 044fac4

Please sign in to comment.