can we have to use onclick function

can we have to use onclick function 

echo elgg_view('input/submit',array(
        'name' => 'click',
        'value' => 'click',
    ));

if yes so how to use?

  • i have use this code in owner_block.php

    <script type="text/javascript" language="javascript">

        function form() {
                var elgg = require("elgg");
                alert("Hello! I am an alert box!!");    
        }
        
    </script>

     

    <?php
        
            echo elgg_view('input/submit',array(
                'name' => 'biolosophy',
                'value' => 'Biolosophy',
                'onclick' => 'javascript:form()',            
            ));

    ?>

  • Don't use inline javascript. Create a new AMD module.

    // forms/my-form.js
    
    define(function(require) {
    
       var $ = require('jquery');
       
       $(document).on('click', '.my-form-button-trigger', function(e) {
          alert('hello');
       });
    
    });
    
    
    

     

    ​// forms/my-form.php
    
    echo elgg_view('input/submit', [
       'class' => 'my-form-button-trigger', // this is referenced above
       'name' => null, // use of name is discouraged on submit inputs
       'value' => 'Click Me!',
    ]);
    
    elgg_require_js('forms/my-form');
    
  • Hi Ismayil. I tried it, but it seems not working in my case. I also tried according to the official doc: http://learn.elgg.org/en/2.3/guides/javascript.html, but couldn't get it working as well. Below is example of some of my code:

    // service/views/default/service/hello_world.js
    
    define(function(require) {
        var elgg = require("elgg");
        var $ = require("jquery");
    
        $('body').append(elgg.echo('hello_world'));
    });
    
    
    // service/views/default/resources/service/all.php
    ....
    elgg_require_js("service/hello_world");​

    In Chrome console, I can see the error: `require.js:168 Uncaught Error: Mismatched anonymous define() module: function (require) {`. 

  • Hm. Odd. Should work. The only thought is to try a different module name. Service can be a reserved word somewhere.

  • Hi everyone I am using the same technique and everything seems to work my javascript function is call but the require form field are not control (the form is submit without form control).

    Could someone help me to know what's wrong ?

    Best regard

     

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking