Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: inputText option for $ionicPopup.prompt() #1589

Closed
danielzen opened this issue Jun 8, 2014 · 10 comments
Closed

Feature Request: inputText option for $ionicPopup.prompt() #1589

danielzen opened this issue Jun 8, 2014 · 10 comments

Comments

@danielzen
Copy link

I want to create an edit text prompt by pre-populating the input text:

$ionicPopup.prompt({
  title: 'Edit Text:',
  inputText: 'I want to put editable text here', 
})

instead in beta.6 I had to write :(

var scope = $scope.$new(true);
scope.data = {response: 'This is editable text' };

$ionicPopup.prompt({
  title: 'Edit Text:',
  scope: scope,
  buttons: [
    { text: 'Cancel',  onTap: function(e) { return false; } },
    {
      text: '<b>OK</b>',
      type: 'button-positive',
      onTap: function(e) {
        return scope.data.response
      }
    },
  ]
})
@perrygovier
Copy link
Contributor

Hey @danielzen, between the inputPlaceholder and the return value passed to the then() callback, I'm not sure what's missing. Could you shed a bit more light on what you're trying to achieve?

@danielzen
Copy link
Author

inputPlaceholder is only a placeHolder, not editable...

PlaceHolder text gets immediately overwritten? I want to pre-populate the actual input value, not just a temporary one. I created a codepen to illustrate:

http://codepen.io/danielzen/pen/sqLfa

@danielzen
Copy link
Author

PS: I tried to take advantage of the fact that I knew, under the hood, that data.response was the ng-model that prompt was using:

http://codepen.io/danielzen/pen/kotEw

However, this stopped the then() from getting the right response value, which is why I had to create custom buttons to get the desired result.

@perrygovier
Copy link
Contributor

Ah, i see. I'll take a look. Thanks!

@ajoslin
Copy link
Contributor

ajoslin commented Jun 11, 2014

@danielzen You can always use a template!

For example:

$scope.data = { text: '123' };
$ionicPopup.show({
  templateUrl: "my-template.html",
  scope: $scope
});
<script type="text/ng-template" id="my-template.html">
  <input ng-model="data.text">
</script>

@ajoslin ajoslin closed this as completed Jun 11, 2014
@GreenImp
Copy link

GreenImp commented Aug 7, 2014

Is a template really the only way to achieve this? I would have thought that something like that would already be implemented, in pretty much the exact way that @danielzen has described.

Is it something that may be implemented in the future?

@danielzen
Copy link
Author

The number of extra lines required for this common functionality seems
excessive for a framework that is supposed to be about brevity.

@ajoslin: I do not believe your solution is complete. I have tried what you
proposed and needed more custom code to get it to work. Please look at my
functional examples on codepen, and could you show a simpler solution if
possible? I had to also create custom button handlers.

@vincentjames501
Copy link

I think that this is a common enough scenario that this option should be added. Using a template seems like the opposite of 'brevity' in this case.

@WhatsThatItsPat
Copy link

I expected this option to be there, similar to ngCordova's defaultText for prompts.

@danielzen
Copy link
Author

I keep thinking I'm going to just add the feature in myself, and make a
pull request, but sadly I have not :(

This is the hack I have been using:

https://github.com/danielzen/todo-ng-pouchdb/blob/master/www/js/app.orig.js

$scope.editTask = function(task) {
  $scope.data = { response: task.title }; // A hack to pre-populate prompt
    $ionicPopup.prompt({
      title: "Edit Task",
      scope: $scope
    }).then(function(res) {    // promise
      if (res !== undefined) task.title = $scope.data.response; // response not res has new title (hack)
      $ionicListDelegate.closeOptionButtons();
    })
  };
})

I expected this option to be there, similar to ngCordova's defaultText for
prompts.


Reply to this email directly or view it on GitHub
#1589 (comment).

mlynch added a commit that referenced this issue Dec 6, 2015
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants