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
Posted (edited)

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...