tags input requested

General questions relating to Joomla! 3.x. Please consider the availability of third-party templates and extensions when deciding which Joomla version to use.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Post Reply
fujisan
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Wed Sep 05, 2018 1:51 am

tags input requested

Post by fujisan » Thu Oct 11, 2018 5:49 am

Hi,

I'd like to enter tags mandatory when posting articles from the frontend.
How can I do this? Is there a way?

thank you.

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1174
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: tags input requested

Post by SharkyKZ » Thu Oct 11, 2018 6:05 am

This can be done with a content plugin that alters the form:

Code: Select all


defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;

class PlgContentExample extends CMSPlugin
{
	protected $app;

	public function onContentPrepareForm($form, $data)
	{
		if (!$this->app->isClient('site') || $form->getName() !== 'com_content.article')
		{
			return true;
		}

		$form->setFieldAttribute('tags', 'required', 'true');
	}
}

annahersh
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 222
Joined: Wed Aug 15, 2018 8:23 pm

Re: tags input requested

Post by annahersh » Thu Oct 11, 2018 6:23 am

Try the following jquery in your template's index.php within the php section at the top. I haven't tested it so there's no confirmation that it works.

Code: Select all

$this->addScriptDeclaration('
jQuery(function($) {
$("select#jform_tags").attr({
    "required": "required", 
	"aria-required": "true"
});

// assuming the class attrib exists. If not, add to the attr array
$("select#jform_tags").addClass("required");
});
');

SharkyKZ
Joomla! Ace
Joomla! Ace
Posts: 1174
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: tags input requested

Post by SharkyKZ » Thu Oct 11, 2018 7:04 am

Relying on client-side validation only. What could go wrong? :pop

fujisan
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Wed Sep 05, 2018 1:51 am

Re: tags input requested

Post by fujisan » Fri Oct 12, 2018 3:05 pm

hi, SharkyKZ

Is your pointed out 'content plugin' the following program? Should I add or modify your code in that program?
root) plugins> content> joomla> joomla.php

Please let me know if it is wrong.

thank you.

fujisan
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Wed Sep 05, 2018 1:51 am

Re: tags input requested

Post by fujisan » Fri Oct 12, 2018 3:22 pm

hi, annahersh

I am a program beginner. So ,Where should I place your code in the 'index.php' of the template (which is a vertex?)
Is it just under <head> or before end?

thank you

fujisan
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Wed Sep 05, 2018 1:51 am

Re: tags input requested

Post by fujisan » Fri Oct 12, 2018 3:38 pm

Hi, SharkyKZ

>Relying on client-side validation only. What could go wrong?

We are developing a site of sports event navigation right now.
The site is an organization posting event articles by organizing it.

However, there are many web beginners in those organizations, and I am worried about forgetting to designate tags (this is a kind of sports, eg 'tennis').
Of course, we will explain it before publishing the site.
But that is not enough.

regards


Post Reply

Return to “General Questions/New to Joomla! 3.x”