Ad Widget

Collapse

Widget development - simple question

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • omar.cacciotti
    Junior Member
    • Jul 2021
    • 25

    #1

    Widget development - simple question

    Hello mates!
    In these years I have been waiting for a Sticky Notes style widget to be created to add to the dashboard to leave information to the first level operators.
    In the end I decided to create it, since it is quite simple in design, but I have a problem..
    The text area does not go to the next line and I do not know how to make a new line.

    I attach a screenshot



    Click image for larger version  Name:	image.png Views:	6 Size:	48.4 KB ID:	499600

    How I can do that?

    here the essential lines:

    Code:
    views/widget.edit.php: new CWidgetFieldTextAreaView($data['fields']['testo'])
    includes/WidgetForm.php: use Zabbix\Widgets\Fields\CWidgetFieldTextArea;
    includes/WidgetForm.php: new CWidgetFieldTextArea('testo', _('Insert Text:'))
    Last edited by omar.cacciotti; 25-02-2025, 19:31.
  • Answer selected by omar.cacciotti at 27-02-2025, 13:10.
    omar.cacciotti
    Junior Member
    • Jul 2021
    • 25

    SOLVED

    In order to help someone else, I found the shorten path that helped me.
    I'm not a developer, so the needs are hard to satisfy, but I also didn't found the proper documentation about views, just few lines.
    Would be really cool to get a documentation about all classes and more to get people able to develop simple things such as this widget.

    At the end i solved by using CPre instead of CDiv.

    How I did it:

    I had to "ls -lart /usr/share/zabbix/ui/include/classes/html" and look at all .php files.

    here the new code:

    <?php

    Code:
    /**
    * Gauge chart widget view.
    *
    * @var CView $this
    * @var array $data
    */
    
    (new CWidgetView($data))
    ->addItem(
    new CTag('h1', true, $data['description'])
    )
    ->addItem(
    new CPre($data['testo'])
    )
    ->show();
    
    ?>
    And this is the result I want:

    Click image for larger version

Name:	image.png
Views:	83
Size:	16.0 KB
ID:	499722

    Thank you anyway

    Comment

    • gcalenko
      Zabbix developer
      • Mar 2017
      • 27

      #2
      I suppose you are using a CTag-based class to render the note. They should automatically escape the content to prevent the injection of HTML tags or even JavaScript. Could you show the PHP code of your widget.view? If your code is available on any Git platform and you can share the link, that would be excellent.

      Comment

      • omar.cacciotti
        Junior Member
        • Jul 2021
        • 25

        #3
        Originally posted by gcalenko
        I suppose you are using a CTag-based class to render the note. They should automatically escape the content to prevent the injection of HTML tags or even JavaScript. Could you show the PHP code of your widget.view? If your code is available on any Git platform and you can share the link, that would be excellent.
        Hi gcalenko , thank you for the answer, here my code (I did not published the code yet)

        Code:
        <?php
        
        /**
        * Gauge chart widget view.
        *
        * @var CView $this
        * @var array $data
        */
        
        (new CWidgetView($data))
        ->addItem(
        new CTag('h1', true, $data['description'])
        )
        ->addItem(
        new CDiv($data['testo'])
        )
        ->show();
        The text is in CDiv element

        Comment

        • omar.cacciotti
          Junior Member
          • Jul 2021
          • 25

          #4
          SOLVED

          In order to help someone else, I found the shorten path that helped me.
          I'm not a developer, so the needs are hard to satisfy, but I also didn't found the proper documentation about views, just few lines.
          Would be really cool to get a documentation about all classes and more to get people able to develop simple things such as this widget.

          At the end i solved by using CPre instead of CDiv.

          How I did it:

          I had to "ls -lart /usr/share/zabbix/ui/include/classes/html" and look at all .php files.

          here the new code:

          <?php

          Code:
          /**
          * Gauge chart widget view.
          *
          * @var CView $this
          * @var array $data
          */
          
          (new CWidgetView($data))
          ->addItem(
          new CTag('h1', true, $data['description'])
          )
          ->addItem(
          new CPre($data['testo'])
          )
          ->show();
          
          ?>
          And this is the result I want:

          Click image for larger version

Name:	image.png
Views:	83
Size:	16.0 KB
ID:	499722

          Thank you anyway

          Comment

          Working...