twitter-bootstrapalertify

Alertify prompt not working


I recently grabbed a copy of the Alertify library but I can't get prompt to work.

My app is .NET MVC using Bootstrap.

This is a snip of my my html (removed most of the option tags for visibility):

<div class="row">
    <div class="col-md-3">
        Model
    </div>
    <div class="col-md-9">
        <select id='selmodels' class='w250' type='model'><option class='w250' value='0'></option></select>
        &nbsp;
        <div id="edit" class="btn btn-default">Edit</div>
    </div>
</div>

This is the script (this was different but changed to the alertify example while debugging):

$(document).ready(function () {

    $('#edit').click(function () {
        //var name = $('#selmodels option:selected').text();
        alertify.prompt('This is a prompt dialog!', 'some value',
            function(evt, value) { alertify.message('You entered: '  + value); }
        );
        return false;
    });
})

However clicking 'Edit' gives the error:

fn must be a function

What is wrong with this?


Solution

  • It seems to me that you've used incorrect order for the arguments of the prompt method of alertify. The correct template is as follows:

    alertify.prompt('Insert your message here:', function (e, str) {
            if (e) {
                // e corresponds to an "OK" press.
                // str is the value of the prompt textbox.
            } else {
                // else corresponds to a "Cancel" press.
            }
        }, 'Insert the default textbox message here.');
    

    So just change the order of your arguments in the prompt method. Your code in the end should look something like this:

    $(document).ready(function () {
    
      $('#edit').click(function () {
          //var name = $('#selmodels option:selected').text();
          alertify.prompt('This is a prompt dialog!',
              function(evt, value) { alertify.message('You entered: '  + value); }
              'some value'
          );
          return false;
      });
    })