Jump to content
Robin S

HannaCodeDialog

Recommended Posts

@MilenKo, it's not possible to have a required field in the dialog because the dialog form is not submitted anywhere for ProcessWire validation - the field values are just captured via Javascript when the dialog is closed. You should check for empty field values in the code for your Hanna tag.

Incidentally, this is true for any "required" field anywhere in PW because nothing is ever really required - the user can simply abandon the edit process if they want and leave unfilled required fields, so you always need to check that fields are actually populated before doing anything with their value.

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S Thanks for your clarification. I was afraid you would say so, but was just thinking if it would be possible for me to modify the dialogue files and have an extra option added like the other attribute options - something like:

attribute__options=Option1|Option2 but with some extra logic:

attribute__requirements=required or similar.

My idea is that from the dropdown menu, the user is provided a choice of multiple blocks and once one is selected, the dialogue opens up and can intercept an eventual requirement set thorugh the module. Once the user has finished and press OK, if he double clicks on the HC he is still seeing the same code so technically it would be difficult for the user to change the text etc. and is presented a nice "reminder" of an empty attribute or else.

On the other thought, the present functionality might be a better option for me as I am allowing a user to choose a news tab category (1 out of 10) so he can leave 1 empty, 2 empty and then add 3, 4 etc. 

Will see how it would be completted to fit the requirements and avoid any errors as presently I am grouping all the attributes to an array, then have to clean the empty values, then to reorder and then to apply it. But hey, it works and it was super easy for my 8 years old boy I've tested with to add the block, pick categories, limit the number of pages shown etc. GREAT THANK YOU FOR THE EFFORTS AND MODULE!

  • Like 1

Share this post


Link to post
Share on other sites

Btw, is it possible to set the width/height of the dialogue box (width/height) as presently I have about 10 drop-down boxes for categories plus some other limiters to show a specific page count on the block so the scrolling is not very convenient? Maybe I can make the dialogue wider through some options or else? I mean if it is possible to have the options per tag, not by default?

Share this post


Link to post
Share on other sites
16 hours ago, MilenKo said:

I mean if it is possible to have the options per tag, not by default?

No, that isn't possible in this module - the dialog width and height in the module config applies globally to all Hanna tags.

Share this post


Link to post
Share on other sites

@Robin S Thank you for your info. Would it be possible to have an option to set the width and height of the dialogue for all Hanna Tags which would make my options visible better or I would have to set the dimensions by editing the module files?

Share this post


Link to post
Share on other sites
8 minutes ago, MilenKo said:

Would it be possible to have an option to set the width and height of the dialogue for all Hanna Tags which would make my options visible better or I would have to set the dimensions by editing the module files?

As per my previous reply and the module readme there are config options for dialog width and height.

2019-05-03_103012.thumb.png.1fba36d23e2f388488f63b229fffd004.png

Or maybe I don't understand your question.

  • Thanks 1

Share this post


Link to post
Share on other sites

Oh, @Robin S my bad. I don't know how but I've missed to check the module configuration page and was looking at the tag options again. It works perfectly now and I can increase the size from there as most of my tags would require bigger window. Thank you again for the help.

  • Like 1

Share this post


Link to post
Share on other sites

v0.2.1 released.

This is a fairly major update in that there has been quite a bit of refactoring. Please be alert for and report any issues. ProcessWire >= v3.0.0 is now required.

This release adds a new hookable HannaCodeDialog::buildForm() method that lets you build the dialog form in the hook rather than setting inputfield options as pseudo-attributes in the Hanna Code tag settings.

From the readme...

Build entire dialog form in a hook

You can hook after HannaCodeDialog::buildForm to add inputfields to the dialog form. You can define options for the inputfields when you add them. Using a hook like this can be useful if you prefer to configure inputfield type/options/descriptions/notes in your IDE rather than as extra attributes in the Hanna tag settings. It's also useful if you want to use inputfield settings such as showIf.

When you add the inputfields you must set both the name and the id of the inputfield to match the attribute name.

You only need to set an inputfield value in the hook if you want to force the value - otherwise the current values from the tag are automatically applied.

To use this hook you only have to define the essential attributes (the "fields" for the tag) in the Hanna Code settings and then all the other inputfield settings can be set in the hook.

Example buildForm() hook

The Hanna Code attributes defined for tag "meal" (a default value is defined for "vegetables"):

vegetables=Carrot
meat
cooking_style
comments

The hook code in /site/ready.php:

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

    // The Hanna tag that is being opened in the dialog
    $tag_name = $event->arguments(0);

    // Other arguments if you need them
    /* @var Page $edited_page */
    $edited_page = $event->arguments(1); // The page open in Page Edit
    $current_attributes = $event->arguments(2); // The current attribute values
    $default_attributes = $event->arguments(3); // The default attribute values

    // The form rendered in the dialog
    /* @var InputfieldForm $form */
    $form = $event->return;

    if($tag_name === 'meal') {

        $modules = $event->wire('modules');

        /* @var InputfieldCheckboxes $f */
        $f = $modules->InputfieldCheckboxes;
        $f->name = 'vegetables'; // Set name to match attribute
        $f->id = 'vegetables'; // Set id to match attribute
        $f->label = 'Vegetables';
        $f->description = 'Please select some vegetables.';
        $f->notes = "If you don't eat your vegetables you can't have any pudding.";
        $f->addOptions(['Carrot', 'Cabbage', 'Celery'], false);
        $form->add($f);

        /* @var InputfieldRadios $f */
        $f = $modules->InputfieldRadios;
        $f->name = 'meat';
        $f->id = 'meat';
        $f->label = 'Meat';
        $f->addOptions(['Pork', 'Beef', 'Chicken', 'Lamb'], false);
        $form->add($f);

        /* @var InputfieldSelect $f */
        $f = $modules->InputfieldSelect;
        $f->name = 'cooking_style';
        $f->id = 'cooking_style';
        $f->label = 'How would you like it cooked?';
        $f->addOptions(['Fried', 'Boiled', 'Baked'], false);
        $form->add($f);

        /* @var InputfieldText $f */
        $f = $modules->InputfieldText;
        $f->name = 'comments';
        $f->id = 'comments';
        $f->label = 'Comments for the chef';
        $f->showIf = 'cooking_style=Fried';
        $form->add($f);

    }

});
Edited by Robin S
Updated version number
  • Like 7

Share this post


Link to post
Share on other sites

 I have HannaCode that generates a message box. The user is allowed to make some words bold in the 'test' field of the message box:

[[MessageBox type="warning" icon="yes" text="Claims filed between <strong>February 16 - December 10</strong> will receive a partial exemption for that year."]]

The HannaCodeDialog won't recognize this as a valid HannaCode tag though. It just leaves it as is and doesn't convert it to a widget. The same happens if there is a link definition (<a href.....).

Is there any remedy to this?

Share this post


Link to post
Share on other sites

@msavard, in this module HTML tags are not supported inside attributes. But you could use Markdown for the same result, for example:

In your attribute: 

Claims filed between **February 16 - December 10** will receive a [partial exemption](https://www.google.com) for that year.

In your Hanna Tag code:

<div class="message-box"><?= $sanitizer->entitiesMarkdown($text) ?></div>

 

Share this post


Link to post
Share on other sites

That is very helpful, thank you! I didn't even know about that function. I will try it out tomorrow.

 

Share this post


Link to post
Share on other sites

Hey @Robin S I've been playing this weekend with HannaCode + Dialogue and was wondering, would you know a way to provide a label for the attribute options? Presently I have the following list of attributes:

Post_sorting_order
Post_sorting_order__options=date|-date|title|-title|phits|-phits|recipe_comments.count|-recipe_comments.count
Post_sorting_order__description=Negative sign means reverse order

and I am trying to presend the options in a more human readable form (eg. "-date" to become "Date - asscending") etc. It is not much to leave it as it is, however presently to sort by comments count I am using the fieldname.count instead of something like: Comments count (ascending/descending). I've tried to modify the module to have a value of the options like:

Post_sorting_order__options=date*Date(Ascending)|-date*Date(Descending) etc. but so far I was not able to modify the code to make it work..

Share this post


Link to post
Share on other sites
1 hour ago, MilenKo said:

would you know a way to provide a label for the attribute options?

This is possible if you use a hook to build the dialog form. See the example in the module readme. You would define the options like this:

$wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) {

	// The Hanna tag that is being opened in the dialog
	$tag_name = $event->arguments(0);

	// Other arguments if you need them
	/* @var Page $edited_page */
	$edited_page = $event->arguments(1); // The page open in Page Edit
	$current_attributes = $event->arguments(2); // The current attribute values
	$default_attributes = $event->arguments(3); // The default attribute values

	// The form rendered in the dialog
	/* @var InputfieldForm $form */
	$form = $event->return;

	if($tag_name === 'your_hanna_tag_name') {

		$modules = $event->wire('modules');

		/* @var InputfieldSelect $f */
		$f = $modules->InputfieldSelect;
		$f->name = 'Post_sorting_order';
		$f->id = 'Post_sorting_order';
		$f->addOptions([
			'recipe_comments.count' => 'Recipe comments',
			'-recipe_comments.count' => 'Recipe comments (descending)',
			// etc
		]);
		$form->add($f);

	}

});

Or if you don't want to use a hook you just need to do the work of converting the labels into the values you want to sort by in the Hanna tag code. For example:

switch($Post_sorting_order) {
	case 'Recipe comments':
		$sort = 'recipe_comments.count';
		break;
	case 'Recipe comments (descending)':
		$sort = '-recipe_comments.count';
		break;
	// etc
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Hey,@Robin S thank you very much for the quick and useful info. I was playing with some ifs to have a name in the sorting and then convert it to the actual sorting form, however the 'case' switch seems much cleaner and simpler than my code. I will run a test with it and see how it would come out, but I am sure it would be perfect.

Share this post


Link to post
Share on other sites

Is is possible to use the InputfieldSelectorSelectID module with the Hannacode dialog to make a page selector? Would this be built using some type of hook?

Share this post


Link to post
Share on other sites

v0.3.0 released.

Adds support for PageListSelect and PageListSelectMultiple inputfield types. Also adds support for PageAutocomplete inputfield type but only when used via a HannaCodeDialog::buildForm hook. From the module readme:

Quote

For selecting pages you can use pagelistselect or pagelistselectmultiple. You don't supply select options for these inputfield types.

Quote

PageAutocomplete inputfield type

The PageAutocomplete inputfield type can only be used via a HannaCodeDialog::buildForm hook. See the PhpDoc documentation for the list of inputfield properties that may be set. Particularly findPagesSelector for limiting the pages that may be selected and maxSelectedItems for allowing only a single page selection.

 

10 hours ago, maddmac said:

Is is possible to use the InputfieldSelectorSelectID module with the Hannacode dialog to make a page selector?

@maddmac, I think you must be referring to PageListSelect which is used in InputfieldSelectorSelectID rather than that module as a whole. In v0.3.0 you can now use PageListSelect with HannaCodeDialog, either by setting a "attributename__type=pagelistselect" attribute in the tag settings or by using a HannaCodeDialog::buildForm hook.

  • Like 3

Share this post


Link to post
Share on other sites
On 3/20/2020 at 6:53 PM, Robin S said:

Thanks for the info Robin. I did upgrade to 3.0. PageListSelect does appear to now display in Hanna Dialog but when I select the desired page the information is not being added back to the editor. 

See below

[[button_link title="LEARN MORE" pageid=""]]

I am using inside a Repeater Matrix


On 3/20/2020 at 6:53 PM, Robin S said:

 

 

v0.3.0 released.

Adds support for PageListSelect and PageListSelectMultiple inputfield types. Also adds support for PageAutocomplete inputfield type but only when used via a HannaCodeDialog::buildForm hook. From the module readme:

 

@maddmac, I think you must be referring to PageListSelect which is used in InputfieldSelectorSelectID rather than that module as a whole. In v0.3.0 you can now use PageListSelect with HannaCodeDialog, either by setting a "attributename__type=pagelistselect" attribute in the tag settings or by using a HannaCodeDialog::buildForm hook.

 

Share this post


Link to post
Share on other sites

@maddmac, I tested here inside a repeater and it's working correctly.

You might need to clear cached files from your browser to get the updated CKEditor plugins that are included in the module. As far as I know plugins don't get automatic cache busting in CKEditor and I don't know any way to do this manually due to the way external plugins are loaded.

If you do a hard refresh in Page Edit it should fix things.

  • Like 1

Share this post


Link to post
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.

  • Similar Content

    • By MoritzLost
      Process Cache Control
      This module provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Clear the ProCache page render cache (if your site is using ProCache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Plans for improvements
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory CHANGELOG in the repository Screenshots


    • By Macrura
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
×
×
  • Create New...