Announcement

Collapse
No announcement yet.

Sweet Alert - A Beautiful Replacement for Javascript "Alert"

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sweet Alert - A Beautiful Replacement for Javascript "Alert"

    Does anyone know how to implement sweet alert in Scriptcase => control application?

    I have downloaded the source code and uploaded to the External Library under Public.

    I initialise at ScriptINI event or onLoad event but was not able to get it work

    ?>
    <script type="text/javascript" src="<?php echo sc_url_library('sys', 'sweetalert', 'sweet-alert/dist/sweetalert.min.js'); ?>"</script>

    <link rel="stylesheet" type="text/css" href="<?php echo sc_url_library('sys', 'sweetalert', 'sweet-alert/dist/sweetalert.css'); ?>"/>
    <?php

    In addition, by defining these two statement, my javascript script defined in onLoad event does not function anymore

    echo "

    <style>

    #main_table_form{background-size: 100% 100%;
    }
    </style>
    ";

    ?>

    <html>
    <head>
    <script type="text/javascript">

    function startTime()
    {

    var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

    var days = ['Sunday','Monday','Tuesday','Wednesday',
    'Thursday','Friday','Saturday'];


    var d= new Date();
    var weekday = d.getDay();
    var year = d.getFullYear();
    var month = d.getMonth();
    var day = d.getDate();

    document.getElementById("txtTime").innerHTML= d.toLocaleTimeString();
    document.getElementById("txtDate").innerHTML= days[weekday] + ", " + monthNames[month] + " " + day + ", " + year;

    setTimeout('startTime()',1000);

    }
    </script>


    </head>

  • #2
    I have installed from some years ago and works fine.
    I created the folder called sweet into the _lib
    ONLOAD:
    echo '<link rel="stylesheet" href="../_lib/sweet/sweet-alert.css" />';
    echo '<script src="../_lib/sweet/sweet-alert.min.js"></script>';

    Comment


    • #3
      Thank alvagar.

      However, I still could not get it to work. Now I could not even compile my application.

      It just hang at Generating source-code.

      Comment


      • #4
        To resolve the compilation problem: -

        For Control Application, the declaration need to be in the OnScriptInit Event
        ?>
        <script type="text/javascript" src="<?php echo sc_url_library('sys', 'sweetalert', 'sweet-alert/dist/sweetalert.min.js'); ?>"</script>

        <link rel="stylesheet" type="text/css" href="<?php echo sc_url_library('sys', 'sweetalert', 'sweet-alert/dist/sweetalert.css'); ?>"/>
        <?php


        alvagar - How do you call the swal() function?

        In the onValidate Event -

        if (isset({rs[0][0]})) // Row found
        {
        ....
        }
        else
        {
        ?>

        <script>
        swal({
        title: "Error!",
        text: "Here's my error message!",
        type: "error",
        confirmButtonText: "Cool"
        });
        </script>

        <?php
        }


        However, when inspect the code using Chrome, it shows "Uncaught ReferenceError: swal is not defined()"

        Comment


        • #5
          i use a button Javascript for that, i do not use the event onvalidate. Into the button Javascript you can call the function swall.
          and then can call a button php: $('#sc_MyButtonPhp_top').click();

          Comment


          • #6
            Does this mean that scriptcase include library sc_url_library is not working?
            Anyone has any insight of this?

            Comment


            • #7
              I solve the problem.... Here is how I did it.. Hope it will benefit the rest of the community.

              1. First I uploaded the sweetalert.css and sweetalert.min.js files to the External libraries under "Project"

              2. Open the control application which I want to make use of the sweet-alert libraries and then open the External Libraries from Tools, and then click on the library that was created and select "Use Library" this will create the folders and files of sweet alert to your application "_lib/libraries/grp" location

              3. OnLoad event - place the following initialisation code:
              echo '<link rel="stylesheet" href="../_lib/libraries/grp/sweet/sweetalert.css" />';
              echo '<script src="../_lib/libraries/grp/sweet/sweetalert.min.js"></script>';

              4. Create a PHP Methods - I call it "ValidateFail" and create a parameter "msg"

              /**
              * Call a Javascript function after an AJAX call
              */

              // Javascript function parameters
              $javascript_function = 'ErrorMsg'; // Javascript function name
              $javascript_parameters = array($msg);

              // Call javascript function
              sc_ajax_javascript($javascript_function, $javascript_parameters);


              5. Create a JavaScript Methods - with the name defined in the "ValidateFail" for this case "ErrorMsg" and create a parameter "errmsg"

              swal({
              title: "Error!!!",
              text: errmsg,
              type: "error",
              timer: 5000,
              showConfirmButton: false
              });

              6. onValidate Event

              sc_set_global($success);
              .....

              sc_lookup(rs, $check_sql);

              if (isset({rs[0][0]})) // Row found
              {
              {field1} = {rs[0][0]};
              $success=true;

              }
              else // No row found
              {
              $error_message = 'This is an Error Message';
              $success=false;

              }


              7. OnValidateSuccess event - call the sweet alert error message

              if ($success)
              {
              ....
              }
              else
              {
              ValidateFail($error_message);
              }

              Comment


              • #8
                Originally posted by leatheric View Post
                I solve the problem.... Here is how I did it.. Hope it will benefit the rest of the community.

                1. First I uploaded the sweetalert.css and sweetalert.min.js files to the External libraries under "Project"

                2. Open the control application which I want to make use of the sweet-alert libraries and then open the External Libraries from Tools, and then click on the library that was created and select "Use Library" this will create the folders and files of sweet alert to your application "_lib/libraries/grp" location

                3. OnLoad event - place the following initialisation code:
                echo '<link rel="stylesheet" href="../_lib/libraries/grp/sweet/sweetalert.css" />';
                echo '<script src="../_lib/libraries/grp/sweet/sweetalert.min.js"></script>';
                Thanks a lot for taking time to share .. save my day !

                Comment


                • #9
                  Its now available as part of SC 9.4

                  Comment

                  Working...
                  X