How can I get an HTML value with Impromptu?

Advertisements

I’m using impromptu jQuery plugin to show modal prompts for users. I added input type="text" in html section but don’t know how to get this value to send it via ajax.

var statesdemo = {
    state0: {
            title : response.confirm_title,
            html:response.confirm_msg,
            buttons: { Cancel: false, Next: true },
            focus: 1,
            submit:function(e,v,m,f){
                    if(v){
                            e.preventDefault();
                            $.prompt.goToState('state1');
                            return false;
                    }
                    $.prompt.close();
            }
    },
    state1: {
            title : response.confirm_title,
            html:'<div class="form-group"><label for="user_input_msg">'+response.confirm_label+':</label><input type="text" class="form-control" id="user_input_msg" placeholder="'+response.confirm_placeholder+'"></div>',
            buttons: { Back: -1, Done: 0 },
            focus: 1,
            submit:function(e,v,m,f){
                    e.preventDefault();
                    //e.stopPropagation
                    console.log(e);

                    

                    /*
                    if(v==0){ // if done button was pressed, go to the url (or do ajax stuff...)

                            var req = ajax.request[action];
                            req.confirmed = 1;
                            req.input_text = '??????';
                            ajax.exec(req);
                    }
                    else if(v==-1){
                            $.prompt.goToState('state0');
                    }
                    else{
                            ajax.clearActionState(action);
                    }
                     */


            }
    }
};

$.prompt(statesdemo);

>Solution :

f in your case will contain an object generated by iterating over serializeArray which requires inputs to have a name. If you give your input a name, it will then be accessible from f['the-input-name']

(source code for the logic that generates f and triggers the event)
https://github.com/trentrichardson/jQuery-Impromptu/blob/master/src/jquery-impromptu.js#L276C35-L276C61

Leave a ReplyCancel reply