Display more of a hidden text on button click, php, phalcon

Birdy Kun

I have a table that displays items from a database. One of the items is a description so it can be very long.The thing I'm having the most problem with is how can I use JS and HTML smoothly in my controller class.

I want to be able to display a little bit of it if its longer than 100 char, and a button that looks like '...' where if the user clicks on it, it displays the trimmed text. I want to do this using javascript and here is what I tried, this code is in my controller, so I'm just sending these to the view.

The problem is when I press the button it doesn't display anything so what is wrong here? Some suggested to use jquery but I don't want to write my js script elsewhere and call it again since I'm not sure how I will do that in Phalcon controller.

    $this->view->tblColumns = [
            'element one',
            'element two',
            function (tablename $instance) {
                if (strlen($desc = $instance->getDescription()) > 100) {
                    return $shortDesc = substr($instance->getDescription(), 0, 100) . '
<button style="background: none;border: none" onclick="(function(){
    var desc= <?php echo
    $desc; ?>; document.write(desc) ;
})()" >...</button>';

                } else {
                    return $instance->getDescription();
                }
            },
Birdy Kun

I find a way to do what I wanted, using the code for read more,read less from this link https://codepen.io/maxds/pen/jgeoA The thing I was having trouble with in phalcon MVC, was that I didn't know I could my java-script, and css in the view of the controller and that's what I did. I just used the js from that link, into my view file, the same for the css using tag and tag. And in the function on the controller I wrote the following `

$this->view->tblColumns = [
            'one',
            'two',
            function(tablename $link){
            $desc=$link->getDescription();
                $html=<<<HTML
             <span span class="more"> $desc</span>
                  HTML;
                return $html;
            }`

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Show more button hidden after click

hidden text is not visible on button first click

Use selenium to click button and view more text

Want to display more information when i click on see more button

Catching text hidden behind a "read more" button with Selenium

On radio button click text box should display

Button change text display every after click

Toggle hidden & visable text on button click - Kotlin Android Studio

Button click: hidden list

How to display the next three images click on load more button

How to Display "No More Data" message after Button click in javascript

Cannot display text from text box while button click?

Display button on button click

How to echo input text on button click in php

How to display a hidden div on button click and hide the clicked button in Angular 2?

HTML show more text on button click using javascript

Div hidden until I click text/button, appears, then when I click on another, it disappears and the other one is visible

Wordpress/PHP Loop, Display first 3 items then click to load more

Hidden modal not rendering on button click

Display read more button

Hide Text & display message when we click on Button

How do I display text on button click in React.js

simple tkinter question - button command (display other text on click)

Display Checkboxes on Click of a button

Button and click display

how to display a table after i click on a button in php

Display more Text in fullcalendar

Change Text To Button With hidden and shown

Click link and Insert text from hidden field into input field, more than 1 time and replace the text in the input field