Message dialog triggered dynamically within a page, not from a pre-configured link

Message dialog triggered dynamically within a page, not from a pre-configured link

I have a dynamically generated page where, during the page rendering, I would determine that an error message is to be included in the page, such as to tell the user they entered invalid data in a form.

In my mobile version of the page, I thought it would be nice to pop up an error dialog, to ensure they don't miss the message. I can see that any page can be displayed as a dialog from a link using data-rel="dialog", but is it possible to have the decision to pop up a dialog embedded in the page that is being displayed; i.e. the page content says "I am a dialog..." not the link that calls up the page in the first page.

To give more detail, I have a shopping cart page where the user can increase the quantity of an item in the cart. This potentially causes an error that the retailer doesn't have enough stock, so the quantity refuses to increase and an error message appear. I would like the error message in a dialog, before returning to the page, to say "Sorry, no more available" or something.

Many thanks,
John