0

First of all would like to mention that i am new in Angular JS. I have implemented below code in that i want to change button text (By default button names are "Ok" and "Cancel") .i.e "ok" button text to "Yes" and "cancel" button text to "No" without using modal popup. Is there any other way to implement this ? Its already compatible in all browser.

  $scope.sectionLoad = function (formId, sectionId, parentIndex, index){

        if(confirm("Save data?")){
                $scope.submit($scope.form, pageId, sectorId);
        }
        $scope.search = false;
        $scope.sectionDataLoad(formId, sectionId, parentIndex);

  };
Duckkiee
  • 3
  • 1
  • 7
  • Where is the template? Do you 3rd party modal dialog? – Zen Aug 12 '16 at 15:14
  • Lot of questions about this on stackoverflow ... Not able to tag ur question as duplicate from phone ... But search for "HTML confirm button label" ... – Pras Aug 12 '16 at 15:19
  • You cannot do that with the native confirm() as it is of browser's method. You can use custom modal directives, https://angular-ui.github.io/bootstrap/#/modal – Aks1357 Aug 12 '16 at 15:19
  • Possible duplicate of [Javascript Confirm popup Yes, No button instead of OK and Cancel](http://stackoverflow.com/questions/823790/javascript-confirm-popup-yes-no-button-instead-of-ok-and-cancel) – Pras Aug 12 '16 at 15:22

2 Answers2

0

In short - you can't. There's no sure-fire way to change the buttons in a confirm() dialog. You need to create a custom dialog and use that in place of confirm().

Todd Miller
  • 301
  • 1
  • 6
  • In angular-material.js mentioned as we can set custom message to confirm button: $mdDialogPreset#ok(string) - Sets the confirm "Okay" button text. * - $mdDialogPreset#cancel(string) - Sets the confirm "Cancel" button text. – Duckkiee Aug 12 '16 at 15:21
  • That would be a custom dialog you're referencing from angular-material.js. `confirm()` is the default JavaScript confirmation dialog. – Todd Miller Aug 12 '16 at 15:22
0

Thanks to http://myclabs.github.io/jquery.confirm/

$scope.loadData= function (Id, sectionId, parentIndex) {

                $.confirm({
                    title:"Save confirmation",
                    text: "Do you want to save the section data ?",
                    confirm: function (button) {
                        $scope.submit(Id, sectionId, parentIndex, index, 2);
                        $scope.search = false;
                        $scope.sectionLoad(Id, sectionId, parentIndex, index);
                        alert("Section Data Saved.");
                    },
                    cancel: function (button) {
                        $scope.sectionLoad(formId, sectionId, parentIndex, index);
                        alert("Section data not saved");
                    },
                    confirmButton: "Yes",
                    cancelButton: "No"
                });   
    };
Duckkiee
  • 3
  • 1
  • 7