joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[4.0] Implement char counter for input field, too

Open bembelimen opened this issue 4 years ago • 32 comments

Summary of Changes

Enabled character counter for text fields

Testing Instructions

  1. Apply patch
  2. NPM i
  3. Open components/com_users/forms/registration.xml
  4. Add the following attributes to the "name" field: maxlength="30" charcounter="true"
  5. Go to the frontend registration and check the name field

Actual result BEFORE applying this Pull Request

Nothing different

Expected result AFTER applying this Pull Request

grafik

grafik

bembelimen avatar Sep 27 '21 04:09 bembelimen

Could this option be added to the custom fields as well?

brianteeman avatar Sep 27 '21 07:09 brianteeman

Could this option be added to the custom fields as well?

In theory, it could be added to any (input/textarea) field. Currently I activate it manually in my override via: $form->setFieldAttribute('fieldname', 'charcounter', 'true', 'com_fields'); and it works "out-of-the-box".

But that's currently a "bigger" problem in Joomla! (in my opinion): we use for every field an unique layout (which is good on one side) but therefore are very inconsistent over all (like the suffix/prefix info are only available for normal text fields and not for e.g. number fields etc.). Probably worth to have there a nicer solution.

bembelimen avatar Sep 27 '21 08:09 bembelimen

like the suffix/prefix info are only available for normal text fields and not for e.g. number fields etc.

That is a bug that should be fixed ;)

brianteeman avatar Sep 27 '21 08:09 brianteeman

like the suffix/prefix info are only available for normal text fields and not for e.g. number fields etc.

That is a bug that should be fixed ;)

Yes and no, it's failure by design :) the number field does not extend the text field and the layouts could be one base layout with just different attributes....But I guess this counts for many fields (like all dropdowns etc.)

bembelimen avatar Sep 27 '21 08:09 bembelimen

it's failure by design :)

or by omission

brianteeman avatar Sep 27 '21 08:09 brianteeman

I have tested this item :white_check_mark: successfully on 97294eb193b7cf0b7abef7b02a453e47a40dc1bc


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

brianteeman avatar Sep 27 '21 08:09 brianteeman

@bembelimen I wouldn't enable that before fixing the counter to work nicely for repeatable fields. BTW the project should review the fields compatibility with repeatable fields and patch what's broken (ie a field with a counter in a repeatable will work only for the first instance, all others will miss the counter because there's no event to trigger the initialization...)

dgrammatiko avatar Sep 27 '21 11:09 dgrammatiko

Hi @dgrammatiko do you mean this PR (as the problem is the same with textareas then) or the spreading over all fields?

bembelimen avatar Sep 27 '21 11:09 bembelimen

as the problem is the same with textareas

Yes, the initialization of that script is missing the listener for subform add/removal part

the spreading over all fields?

There are many core fields that have issues or not working at all in subforms. Some are easy to patch (ie this one) others need some more changes

dgrammatiko avatar Sep 27 '21 11:09 dgrammatiko

it will be more of an issue with this field - and I see an issue whereby the capabilities of a custom field are not in sync with an xml field.

I agree that all fields need to be reviewed with subforms - there are already a few open issues but thats beyond the scope here (I think)

brianteeman avatar Sep 27 '21 11:09 brianteeman

it will be more of an issue with this field - and I see an issue whereby the capabilities of a custom field are not in sync with an xml field.

Probably the repeatable versions of input and textarea need also an update to expose this feature (if it's not already exposed, I haven't checked the code, I was commenting on the base that the core fields should play nicely with repeatables). Anyways I provided the code needed

dgrammatiko avatar Sep 27 '21 11:09 dgrammatiko

But that's currently a "bigger" problem in Joomla! (in my opinion): we use for every field an unique layout (which is good on one side) but therefore are very inconsistent over all (like the suffix/prefix info are only available for normal text fields and not for e.g. number fields etc.).

I just checked. Suffix and Prefix are available for every field - it is in the render options

image

image

brianteeman avatar Sep 29 '21 19:09 brianteeman

I have tested this item :white_check_mark: successfully on 97294eb193b7cf0b7abef7b02a453e47a40dc1bc


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

RickR2H avatar Sep 30 '21 14:09 RickR2H

RTC


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

richard67 avatar Oct 03 '21 18:10 richard67

@richard67 my comment is still valid, introducing this without support for repeatable fields is plain wrong 😑

dgrammatiko avatar Oct 03 '21 19:10 dgrammatiko

@richard67 my comment is still valid, introducing this without support for repeatable fields is plain wrong 😑

@dgrammatiko Sorry, was not clear to me that there is something remaining to be done since the PR has got 2 test.

@bembelimen What's the status of this PR? You want to leave it as it is, or do you want to adapt it to support repeatable fields?

richard67 avatar Oct 03 '21 19:10 richard67

Back to pending due to ongoing clarifications.


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

richard67 avatar Oct 03 '21 19:10 richard67

Needs review.


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

richard67 avatar Nov 13 '21 13:11 richard67

This pull request has automatically rebased to 4.2-dev.

HLeithner avatar Jun 27 '22 13:06 HLeithner

This pull requests has been automatically converted to the PSR-12 coding standard.

joomla-bot avatar Jun 27 '22 21:06 joomla-bot

Hi! just using the brand new charcounter param in my edit message form like this

	<field
		name="title"
		type="text"
		label="COM_JAPPPUSH_FIELD_MESSAGE_TITLE_LABEL"
		maxlength="35"
		charcounter="true"
		required="true"
	/>

	<field
		name="body"
		type="textarea"
		label="COM_JAPPPUSH_FIELD_MESSAGE_BODY_LABEL"
		maxlength="160"
		charcounter="true"
	/>

Is it possible to apply this to the text input?

Thanks!


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

mgscreativa avatar Jul 20 '22 13:07 mgscreativa

Is it possible to apply this to the text input?

@mgscreativa Isn't that exactly what this pull request (PR) here here is doing?

If so, please test this PR and then mark your test result by going to the issue tracker here https://issues.joomla.org/tracker/joomla-cms/35678 and then using the blue "Test this" button at the top left corner, selecting the appropriate test result and submitting.

Every PR needs 2 successful tests by a human to get accepted, so if this PR solves your problem then please test it as described to bring it forward. Thanks in advance.

richard67 avatar Jul 20 '22 13:07 richard67

I have tested this item :white_check_mark: successfully on ae922dc3df8ed0c6a6e9f9e5a6d217342e50fcd1

Tested ok, no issues!


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

mgscreativa avatar Jul 21 '22 18:07 mgscreativa

Hi @richard67 done testing, works ok! Hope it gets in J 4.1


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

mgscreativa avatar Jul 21 '22 18:07 mgscreativa

@bembelimen After building I get the error: Uncaught SyntaxError: missing ) after argument list (at short-and-sweet.min.js?1.0.4:10:104) Don't know if it is related, but the counter does not show up. Could you take a look?

RickR2H avatar Jul 29 '22 15:07 RickR2H

@bembelimen After building I get the error: Uncaught SyntaxError: missing ) after argument list (at short-and-sweet.min.js?1.0.4:10:104) Don't know if it is related, but the counter does not show up. Could you take a look?

Previous review comment already mentioned that. There is indeed a syntax error in the js. The closing single quote of a query selector string is missing.

richard67 avatar Jul 29 '22 16:07 richard67

Hi! is there anything else I can do to helpo this PR to pass? I'm using it in my site and it works just fine.

Thanks!

mgscreativa avatar Aug 15 '22 19:08 mgscreativa

As long as @bembelimen does not fix the syntax error in the JS mentioned above, it can not be accepted.

richard67 avatar Aug 15 '22 19:08 richard67

Hi @richard67 can I send another PR with the same changes to try to pass it through?

mgscreativa avatar Aug 17 '22 12:08 mgscreativa

Hi! @bembelimen would yo be so kind to review this typo here to be able to pass this PR? https://github.com/joomla/joomla-cms/pull/35678/files#r926994733

Thanks!

mgscreativa avatar Aug 17 '22 12:08 mgscreativa