Popup message in semantic ui

3

I have a button:

<div class="ui container">
   <a href="#" class="fluid ui violet button"><i class="mail icon"></i>  Enviar Mensaje</a>
</div>

below I have the popup message initialization:

<script type="text/javascript">
  $('.activating.element')
    .popup()
  ;

  $('.ui.popup')
    .popup({
    title   : 'Atención:',
    content : 'Esta funcionalidad sólo está disponible para usuarios registrados'
  })
  ;
</script>

How do I link that popup message with the button I defined above? I read the documentation but I did not understand.

    
asked by MNibor 15.07.2017 в 14:55
source

2 answers

2

You are applying an incorrect selector when you indicate to semantic the element (button in this case) that you want to activate the popup. You could use for example .ui.button in the JavaScript selector, without changing the current html, but it can be too generic. My suggestion is that you add another more personalized class, which indicates the purpose of the popup, which in this case is to notify that this functionality is available only to registered users, so I wrote .registered-only

$('.registered-only')
    .popup({
    title   : 'Atención:',
    content : 'Esta funcionalidad sólo está disponible para usuarios registrados'
  })
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.11/semantic.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.11/semantic.js"></script>
<div class="ui container">
   <a href="#" class="fluid ui violet button registered-only"><i class="mail icon"></i>  Enviar Mensaje</a>
</div>
    
answered by 15.07.2017 / 17:59
source
1

You can do it using the click() jquery method.

First we assign a id="enviar-msg-button" to the button to be able to identify it:

<div class="ui container">
       <a href="#" id="enviar-msg-button" class="fluid ui violet button"><i class="mail icon"></i>  Enviar Mensaje</a>
    </div>

Then we look for the button by its id and we say that when clicking, our popup is executed:

 $("#enviar-msg-button").click(function(){

  $('.activating.element').popup();

  $('.ui.popup').popup({
    title   : 'Atención:',
    content : 'Esta funcionalidad sólo está disponible para usuarios registrados'
  });
})
    
answered by 15.07.2017 в 15:28