digicorp / propeller

Propeller - Develop more, Code less. Propeller is a front-end responsive framework based on Google's Material Design Standards & Bootstrap.
http://propeller.in
MIT License
1.13k stars 141 forks source link

[FEATURE] . Alerts could be triggered by javascript #54

Closed jpkontreras closed 6 years ago

jpkontreras commented 6 years ago

Im having kinda of a harsh time using this library alerts. i want to use it to tell the user that an ajax call was successful, but when i try the "js || jquery way"

 <button type="button"
                id="success"
                data-positionX="center"
                data-positionY="top"
                data-duration="5000"
                data-effect="fadeInUp"
                data-message=""
                data-type="information"
                data-revert="fadeOutUp"
                class="btn pmd-ripple-effect btn-info pmd-btn-raised pmd-alert-toggle">
        </button>

document.getElementById('success').click();
$('#success').trigger('click');
$('#success').click()

The alerts aren't being erased. image

Must be cool if they trigger with the same jquery you guys are using.

Neat library btw .

sunil-digicorp commented 6 years ago

Hi jpkontreras,

We are unable to understand exactly where and how are you facing the issue with the alerts.

Still, please find the below code snippet for example where the alert is called using AJAX.

//html
<button type="button" data-positionX="right" data-positionY="top" data-duration="3000" data-effect="fadeInUp" data-message="" data-type="" class="btn pmd-ripple-effect btn-warning pmd-z-depth alert-trigger pmd-alert-toggle floating_alert_button hidden">Alert Warning</button>

//js common function
function showFloatingAlertMessage(msg, type){
    if(typeof msg != 'undefined' && msg != '' && typeof type != 'undefined' && type != '') {
        //change type
        if(type == 'danger') {
            type = 'error';
        }
        element = $('.floating_alert_button');
        $(element).attr('data-type', type);
        $(element).attr('data-message', msg);
        $(element).trigger('click');
        return;
    }
    alert('fallback error!');
}
//on ajax success
showFloatingAlertMessage('your messages', 'danger');
showFloatingAlertMessage('Your message', 'warning');
showFloatingAlertMessage('Your message', 'success'); 

Please check if this helps.

If still you are facing an issue, please share a detailed code snippet or a step by step procedure you follow for our better understanding.

Please feel free to ask in case of any further queries.

alopez25 commented 6 years ago

Could you also share how can I trigger an alert message with JS but not by clicking a button. I'm using Ruby on Rails and I'd like to trigger alerts programmatically from a controller as a result of some user input. Thanks