jquery-alertable icon indicating copy to clipboard operation
jquery-alertable copied to clipboard

Pre-fill default text in prompt mode

Open asantos opened this issue 6 years ago • 3 comments

Is it possible to pre-fill a default text for the input in the prompt mode? (just what the javascript native prompt 2nd parameter does).

asantos avatar Mar 01 '19 13:03 asantos

Not currently, but good idea. It would be easy to add as another option in the show method, which would get passed through this prompt options.

A bonus option would be a way to specify text selection too (e.g. if you’re renaming a file and only want to select the file name, not extension).

claviska avatar Mar 01 '19 14:03 claviska

I'd say, that if a defaultValue for the prompt input is defined in the options, it should be directly .select() instead of .focus()

asantos avatar Mar 01 '19 17:03 asantos

This actually can be done by altering the default "prompt" option, like this:

                    $.alertable.prompt('Change price to:', {
                                                            html: true,
                                                            prompt: '<input class="alertable-input" type="text" name="value" value="' + currentprice + '">',
                                                            okButton: '<button class="alertable-ok" type="submit">Continue</button>',
                                                            cancelButton: '<button class="alertable-cancel" type="button">Cancel</button>'
                    }).then(function(data) {
                        var new_price = data['value'];
                    });

stwangner avatar Feb 25 '20 15:02 stwangner