4

I am working in jQuery UI and am trying to figure out a way for a way to pass in custom data fields through the buttons options array. I would like to pass in fields like the example below. data-example & data-example2. Is this possible to do through the buttons param??

<button type="button" data-example="XXXX" data-example2="YYYY" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" ><span class="ui-button-text">xxx</span></button>

here is my create dialog code -

options = {
                autoOpen: true,
                buttons : [
                    {text:"example1"},
                    {text:"example2"}
                ]
            }
jQuery("<div class='dialog' title='xxx'><p>xxx</p></div>")
            .dialog(options);

http://api.jqueryui.com/dialog/#option-buttons

2 Answers 2

14

This example should help.

$(function() {
   $( "#dialog" ).dialog({ buttons: [ { id:"test","data-test":"data test", text: "Ok", click:    function() {alert($('#test').data('test')); $( this ).dialog( "close" ); } } ] });
});

http://jsfiddle.net/9g6jM/

Sign up to request clarification or add additional context in comments.

Comments

0

You can set jQuery UI buttons attributes when the dialog is opened or when you need in your code.

Code:

$("#demo")
    .dialog({
    autoOpen: true,
    buttons: [{
        text: "example1"
    }, {
        text: "example2"
    }],
    open: function (event, ui) {
        $(":button:contains('example1')").attr("data-example", "XXX").attr("data-example2", "YYY");
    }
});

The code select the jQuery UI button example1 and set its data attributes.

Demo: http://jsfiddle.net/IrvinDominin/BKHEn/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.