Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get an HTML value with Impromptu?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading