Jump to content

Repeatable Fields


ryan

Recommended Posts

  • 4 months later...
  • 6 years later...

Hi,

I have strange bug :
Minutes in a date field are not fine in my repeater field.
If I display 2023-04-03 18:30:00 it shows the minutes as 06 instead of 30.

  1.  I checked up the date in the database it is fine.
  2. I checked up replacing the result in my page by the string, it works.
  3. I tried with strftime then I formatted with the date function for hour and minutes I still have 06mn

Thank you for any help

code.png

date.png

Link to comment
Share on other sites

Hey @Sten,

Sounds like your field (moment) may be configured to output a date that strtotime doesn't understand. You could test by seeing what "echo $event->moment" returns; is it "2023-04-03 18:30:00" or something else?

Anyway, one way to resolve this would be to replace "$moment=strtotime($event->moment)" with $event->getUnformatted('moment'). This will return a timestamp, so strtotime is no longer required.

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, teppo said:

Anyway, one way to resolve this would be to replace "$moment=strtotime($event->moment)" with $event->getUnformatted('moment'). This will return a timestamp, so strtotime is no longer required.

Thank you very much Teppo, it worked fine.

  • Like 1
Link to comment
Share on other sites

19 hours ago, Sten said:

How could it be possible to put the "Add new" link at the top of the page administration?

This is the same UX issue I always encounter with "ProFields: Page Table" (aka FieldtypePageTable) as well.

So far, I have only solved it for Page Table, but I guess you could do something similar in your case as well.

I used JavaScript for the admin to clone the button, like this:

/*
 * Adds a clone of the PageTable field's Add New button to the top of the table
 */
function clonePageTableAddButton() {
    $(".InputfieldPageTableButtons").each(function () {
        $myButtons = $(this);
        $myTableContainer = $myButtons.closest(".InputfieldPageTableContainer");
        //Only add button when Table is not empty (length != 0) and no button has been added already (length < 2)
        if ($myButtons.closest(".InputfieldPageTableContainer").find(".AdminDataTable").length != 0 &&
            $myTableContainer.find(".InputfieldPageTableButtons").length < 2) {
            $myButtons.clone().prependTo($myTableContainer);
        }
    });
}

I also had to solve the issue what crops up when the Page Table is updated via ajax calls, so I had to implement a little bit more what I posted above, but if repeatable fields are not updated via ajax, then probably something no too complex to code should be enough to clone the button after the DOM is ready to be manipulated.

Hope this helps.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...