alfredobarron / smoke

Smoke form validation and components for Bootstrap
http://alfredobarron.github.io/smoke
GNU Lesser General Public License v3.0
387 stars 64 forks source link

[Alert] - Can content be pull in dynamically? #40

Closed emage closed 9 years ago

emage commented 9 years ago

Currently I see that the messages are baked into the Javascript. Is there a way to inject or target dynamic text? I would like those text to be accessible and translatable by the content team

thanks

misaelrojas commented 9 years ago

Do you have an example more specific that you want to do?

There is many ways to call the smkAlert() function. We used this (http://codepen.io/alfredobarron/pen/tpzrb) example in our page just as example, but you can call to smkAlert() in any event that you want and send the alert text msg as a parameter for example:

instead of:

$('#yourBtnId').click(function(e) {
    e.preventDefault();
    $.smkAlert({
        text: 'You alert text',
        type: 'warning'
    });
});

you can can take the text msg from where you want, e.g.

from an attribute of your button

html: <button class="btn btn-warning" id="yourBtnId" alert="Your Custome Mesage" alert-type=“warning”>Warning</button>

Javascript:

$('#yourBtnId').click(function(e) {
        e.preventDefault();
        $.smkAlert({
        text: $('#yourBtnId').attr('alert'),
        type: $('#yourBtnId').attr('alert-type')
    });
});
misaelrojas commented 9 years ago

or you can do it directly through of the Onclick event on the button. http://codepen.io/alfredobarron/pen/WvrLdQ

and in this way, you can remplace the "custom text" with PHP or something

emage commented 9 years ago

@misaelrojas thanks for the quick reply and helpful recommendation. I tried using the data-type method, but somehow the CSS for the warning is not being read propery -- it has no style:

(http://codepen.io/anon/pen/WvwbGe)

Back to my original question. In our website the content team generally puts text into some database and the webteam calls it like this in .net:

<asp:Literal ID="idButtonCountText" runat="server" />

So as a designer, we simply wrap that in any container or p tag and the text magically appears.

So my question was how to call that into the warning box. Hope these all make sense to you.

My guess is to wrap that line into the data-text.

Thanks!

misaelrojas commented 9 years ago

sorry for my late reply. the error in (http://codepen.io/anon/pen/WvwbGe) was about the quotes but now it is working well.

About the I don't know if something like this work:

$('#yourBtnId').click(function(e) { e.preventDefault(); $.smkAlert({ text: $('#yourBtnId').attr('alert'), type: $('#yourBtnId').attr('alert-type') }); });

I mean, if you you can put your own attributes in you asp. I don't know about asp. but maybe this can help you.

http://weblog.west-wind.com/posts/2009/Oct/15/A-generic-way-to-find-ASPNET-ClientIDs-with-jQuery