Skip to content

Commit 044fac4

Browse files
committed
fix(popup): only override prompt input if template includes HTML
1 parent c336e8e commit 044fac4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: js/angular/service/popup.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,13 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume
464464
function showPrompt(opts) {
465465
var scope = $rootScope.$new(true);
466466
scope.data = {};
467+
var text = '';
468+
if(opts.template && /<[a-z][\s\S]*>/i.test(opts.template) === false){
469+
text = '<span>'+opts.template+'</span>';
470+
delete opts.template;
471+
}
467472
return showPopup( extend({
468-
template: '<input ng-model="data.response" type="' + (opts.inputType || 'text') +
473+
template: text+'<input ng-model="data.response" type="' + (opts.inputType || 'text') +
469474
'" placeholder="' + (opts.inputPlaceholder || '') + '">',
470475
scope: scope,
471476
buttons: [{

Diff for: test/unit/angular/service/popup.unit.js

+11
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,16 @@ describe('$ionicPopup service', function() {
277277
$timeout.flush();
278278
expect($ionicBackdrop.release).toHaveBeenCalled();
279279
}));
280+
it('template should only overwrite prompt input if it includes html', inject(function($timeout) {
281+
spyOn($ionicPopup, '_createPopup');
282+
$ionicPopup.prompt({template: "Tacos!"});
283+
params = $ionicPopup._createPopup.mostRecentCall.args;
284+
expect(params[0].template.indexOf('<span>Tacos!</span>')).toEqual(0);
285+
expect(params[0].template.indexOf('<input')).toBeGreaterThan(6);
286+
287+
$ionicPopup.prompt({template: '<input type="email" />'});
288+
params = $ionicPopup._createPopup.mostRecentCall.args;
289+
expect(params[0].template.indexOf('<input type="email" />')).toEqual(0);
290+
}));
280291
});
281292
});

0 commit comments

Comments
 (0)