Fix for Date element when readonly

Bauer

Well-Known Member
Below is a changed calendar() function from date.php which will fix the bug (I think it is anyhow) in the Date element. I.e. When the Date element it is set as ?readonly? ( ?Allow typing in field? set to ?No?), the image for triggering the calendar datepicker popup should not even be shown, as it only confuses the user. This fixes that.

Hiding the datepicker image button, if readonly, was just a matter of adding 3 variables.
  1. The $readonly var to determine if the element is set to readonly.
  2. The $hide var is used to add the fabrikHide class if readonly.
  3. The $class var is set the appropriate class to restore the rounded corners on the right of the input if the button is hidden.
PHP:
public function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null, $repeatCounter = 0)
    {
        FabrikHelperHTML::loadcalendar();
        $j3 = FabrikWorker::j3();
        $readonly = (is_array($attribs) && $attribs['readonly'] == 'readonly') ? "readonly" : "";
        if (is_array($attribs))
        {
            $attribs = JArrayHelper::toString($attribs);
        }
        $paths = FabrikHelperHTML::addPath(COM_FABRIK_BASE . 'media/system/images/', 'image', 'form', false);
        $opts = $j3 ? array('alt' => 'calendar') : array('alt' => 'calendar', 'class' => 'calendarbutton', 'id' => $id . '_cal_img');
        $img = FabrikHelperHTML::image('calendar.png', 'form', @$this->tmpl, $opts);
        $html = array();
        if ($j3)
        {
            $hide = (empty($readonly)) ? "" : " fabrikHide";
            $class = ($hide == "") ? "input-append" : "input";
            $img = '<button id ="' . $id . '_cal_img" class="btn calendarbutton'.$hide.'">' . $img . '</button>';
            $html[] = '<div class="'.$class.'">';
        }
        $html[] = '<input type="text" name="' . $name . '" id="' . $id . '" value="' . $value . '" ' . $attribs . ' />' . $img;
        if ($j3)
        {
            $html[] = '</div>';
        }
        return implode("\n", $html);
    }

I hope someone can fix that in the github. ...please... and thanks in advance.:)
 
When the Date element it is set as ?readonly? ( ?Allow typing in field? set to ?No?),
There's no "readonly" option for the date element, if you want it readonly you must use the access settings.
?Allow typing in field?=No is not for to set it readonly but to force the user to use the date picker so he can't insert bad formatted date manually.
 
Ahhh, OK - thanks troester. Now I see.:oops:
So my changes would take away the intent of the ?Allow typing in field? setting - duhh, my bad. (...but actually, setting the ?Allow typing in field? does set the date input tag to readonly in the php code - that's where I got that from.) I've been obsessed with this for days now and never thought about using the Access level.

This is my dilemma...
I have 2 timestamp fields in a form that are a 'start_date' and 'end_date' of a subscription. I wanted to display them to the user as ?readonly? ? but couldn?t find a date-related plugin that would display them as I wanted. The closest was the date element ? but I didn?t want the date image that triggers the datepicker popup to be shown at all.

Now, thanks to your enlightenment, I see how to prevent that with the access setting. I expected the date to be shown as a readonly input (dimmed in a box) rather than like an element detail view - but I guess I can live with that.

My original thought was to just use the Timestamp plug-in - but the problem with that element it that it is always set as hidden and there is no way to show it. (Which always seemed silly to me.) But with a few lines of css code I was able to 'fix' that too. Except the Timestamp plugin, as is (because it is assumed to be always hidden), had no function to display the label.:(

ALSO... Using either element, I still wanted to show the 'end_date' based on a modified date of the 'start_date' per the php date_modify function - e.g. date_modify($date, '+1 year');

So, rather than just using css to fix the display issues, I spent an entire day tweaking the Timestamp plugin to allow it to be displayed and 'fix' all else I needed done. I have attached the plugin code with those changes if you want to have a look at it. (only the en-GB language file was changed)
Changes?
  1. Added a 3rd option for ?Display time as?. Besides GMT or Server time there is now ?User time?. If the user has not selected time zone, it defaults to ?Server time?.
  2. Added Yes/No option ?Default to Now? - which will set the timestamp to the current date-time when a new row is added.
  3. Added Yes/No option ?Hidden? ? which will hide the element entirely.
  4. Added Yes/No option ?Read Only? ? which will display the element (dimmed) as readonly.
  5. Added Yes/No option ?Show label? ? which will show or hide the element?s label (name).
  6. Added a input text field ?Adjustment? which will show the timestamp date adjusted by that amount. E.g. ?+1 year? or ?+30 days?.
  7. Replaced the ?Format? input field with 2 input fields ? ?List format? and ?Form Format?.
So now after nearly a week of trying to get this right - it seems like the Date plug-in element will do all I needed after all - except the modified date feature ('Adjustment'), allowing the date to be displayed using the 'User Time' setting from Joomla, and the show/hide label option.

IMO, despite all my time working to make those changes, the Timestamp element should be retired. There is really nothing it does that can't be done using the Date element - and it only confuses the user when deciding whether to use a Date or Timestamp.

Now if Changes #1 and #6 above could be integrated into the Date element, I'd say you've got a 'swiss utility knife' of a Date element for fabrik - and you could trash the Timestamp element altogether. Everyone is always complaining about the size of the fabrik project - and getting rid of every bit of bloat or unnecessary plug-ins helps.

Thanks for the help, troester - and let me know what you think of my proposals - or if you know of any existing way to 'Adjust' the date in the date element. (I can live without the 'User time' feature - though I think most end-users would appreciate that.)
 

Attachments

  • timestamp.zip
    16.3 KB · Views: 128
I can't imagine that anybody will touch the date element - it's complicated enough without modifications.

The timestamp element isn't part of Fabrik core, so it won't confuse anybody who didn't download (or discover) it on purpose. I've never used it but AFAIK it's using a MySQL "timestamp" and it's thought for logging.

If you want an end date depending on start date you may use a calc element.
If you want a default date now+30 days you can use the element's default set to eval.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top