joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.75k stars 3.64k forks source link

config.xml type="calendar" enter only year replacing with 1970 #19993

Closed boomsya closed 6 years ago

boomsya commented 6 years ago

Joomla 3.6.5

<field name="avg_year" type="calendar" default="NOW" label="Year" description="" class="input-small" required="true" format="%Y" showtime="false" todaybutton="false" translateformat="false" />

  1. type "2018"
  2. save config
  3. after config page reloaded - field replaced with "1970"
ghost commented 6 years ago

Can you please update to latest Version?

joomla-cms-bot commented 6 years ago

Set to "open" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/19993

boomsya commented 6 years ago

in DB table #__extensions field "params" is "{"avg_year":"2018"}"

boomsya commented 6 years ago

i will try to reproduce on 3.8.6 on other site

boomsya commented 6 years ago

in Joomla 3.8.6 another behaviour: Joomla always set field to "2018" from "2017" before saving form and params DB field is {"avg_year":"2018"}

when i clicking "Save" button - input field with value "2017" always replacing automatically to 2018 before form sended to server and saved value DB is "2018"

so error still in latest version too. But with other behaviour

boomsya commented 6 years ago

when config.xml field param format="%Y-%m" in Joomla 3.6.5 - saved value is correctly but it is not what i want

boomsya commented 6 years ago

and other error in 3.6.5 happens when i set format="%m-%Y" DateTime::__construct(): Failed to parse time string (01-2018) at position 0 (0): Unexpected character

brianteeman commented 6 years ago

Any tests in 3.6.5 are irrelevant as you should only be using 3.8.6 and that is the only version supported

ggppdk commented 6 years ago

@dgt41

In date-helper.js method Date.parseFieldDate

cannot handle format with only Year ?

dgrammatiko commented 6 years ago

@ggppdk not sure that this is failing at the parser: https://github.com/joomla/joomla-cms/blob/7f0d819042de4edad6a194ed5303443bd1016a59/media/system/js/fields/calendar-locales/date/gregorian/date-helper.js#L278-L285

it might be the print function that is failing but this needs to be debugged to figure out which part is failing. Fwiw both parse and print were not changed in any way when we redid the calendar...

brianteeman commented 6 years ago

Why would you even use a full calendar if you only want the year?

ggppdk commented 6 years ago

yes it seems that this code was not changed

i see that m (month) keeps its initial value -1 when you have format "%Y" the parsing code continues and eventually you get to have "return today";

Date.parseFieldDate = function(str, fmt, dateType) {
....
        var today = new Date();
        var y = 0;
        var m = -1;
        var d = 0;
...
        if (y != 0 && m != -1 && d != 0)
            return new Date(y, m, d, hr, min, sec);
...
        if (m != -1 && d != 0)
            return new Date(y, m, d, hr, min, sec);
        return today;
ggppdk commented 6 years ago

Why would you even use a full calendar if you only want the year?

indeed calendar field does not seem appropriate choice if you only want to select a year

boomsya commented 6 years ago

Why would you even use a full calendar if you only want the year?

because i want. It is normal select year, month with only mouse. Why android using CalendarView? :) everyone can enter date in TextView :) because it is friendly UI. But calendar in Joomla it is pain. Look at this http://t1m0n.name/air-datepicker/docs/index.html it is datepicker on steroids :) in compare to joomla calendar

mbabker commented 6 years ago

Even if the code's busted, this is a case where you're using an inefficient tool for the job. If you really only are offering a year selection and not a full date, you're better off creating a list field with a custom year range than trying to use a calendar to select a year.

infograf768 commented 6 years ago

Look at this http://t1m0n.name/air-datepicker/docs/index.html it is datepicker on steroids :) in compare to joomla calendar

Nice, but limited to Gregorian calendar. Joomla also includes jalali. 😃

ggppdk commented 6 years ago

A drop down for year only selection will also be better ux, fast and easy, understandable

boomsya commented 6 years ago

oh mans. i have some trouble with speaking english. Ok, i will try to explain:

  1. hardcoded values in dropdown list - is not very good.
  2. writing custom "element"? - maybe it is solution. maybe. But good solution is use core based CMS elements
  3. about Jalali and Gregorian - oh, i never saw this. Anybody using this? :) it is just question :)

anyway i hope my exploring with Year format helps somebody

ggppdk commented 6 years ago

hardcoded values in dropdown list - is not very good.

you can use this https://docs.joomla.org/Number_form_field_type

about hardcoding, how is it different than specifying minyear maxyear in calendar filed ? with hard-coding you mean you want different limits per which case ? different limit per language ?

boomsya commented 6 years ago

thanks for solution

i mean what if i will hardcode dropdown in XML: 2016 2017 2018

and after 2-3 years i will need to add in XML: 2019 2020 2021 :(

ggppdk commented 6 years ago

Yes, i see the problem, indeed you need the minyear , maxyear options that the calendar supports

... then extending number form element type of Joomla and customizing it is the way to go

and regardless of fixing the issue you reported here, the above is probably the best UX choice (for the form)

in a previous answer, i mentioned where the issue is, if someone is interested into spend time to fix it https://github.com/joomla/joomla-cms/issues/19993#issuecomment-376144129

infograf768 commented 6 years ago

about Jalali and Gregorian - oh, i never saw this. Anybody using this? :) it is just question :)

We have 2 languages using Jalali: Persian and Dari Persian

tonypartridge commented 6 years ago

Just create a custom element type based on select list which has a starting year and goes 4 years into the future from today. Fairly simple to do, the core calendar isn’t really designed for your usage case, the core cannot think of every use age scenario.

joomla-cms-bot commented 6 years ago

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/19993

Quy commented 6 years ago

Closing for reasons stated above.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/19993.