Jump to content

HannaCodeDialog


Robin S

Recommended Posts

  • 7 months later...
5 hours ago, David Karich said:

the question is whether you have plans to port this module for TinyMCE as well?

Yes, I do intend to create a new module similar to HannaCodeDialog that supports TinyMCE. But I don't have an estimated date for when it will be ready.

For many of my modules, the situation has been that I work on them when I have a need for them myself. And I have quite a number of modules based on CKEditor that I use frequently and that would need to be redeveloped for TinyMCE before I personally can contemplate changing my RTE fields from CKEditor to TinyMCE. So I have quite a lot of work ahead of me and consequently I don't think HannaCodeDialogMCE is going to completed in the very near future.

  • Like 2
Link to comment
Share on other sites

  • 10 months later...

@Robin S something I had noticed when making all variables editable is even if you don't change them from the defaults, it inserts them into the code.

For example, I have a site where I want use this for a mortgage calculator and want to set things like term (years), type (repayment/interest-only), rate (percentage) and so on, but if I only want to change the "type" from repayment (default) to interest only on one page, the hannacode also ends up setting the rate in the code in the editor even though I leave it as the default.

This wouldn't normally be a problem but the site has articles for different terms, repayment types and potentially interest rates, but when interest rates change I change the default rate in the Hannacode, but using the dialog it makes it fixed for that page.

I think if you use the dialog and the value saved == the default value, it just shouldn't appear in the hanna code block.

In my example, this would be the default with no overrides:
 

[[mortgage_calculator]]

And some pages I'll want it to default the mortgage amount:
 

[[mortgage_calculator default_amount="70000"]]

But changing one variable sets them all using HannacodeDialog even though the other values are the default ones:
 

[[mortgage_calculator default_amount="70000" default_rate="4" default_type="repayment" default_term="25"]]

 

On another note I'm also keen to see a TinyMCE version 🥺😅. I know it's a lot harder than this next suggestion, but I did get ChatGPT to write most of a plugin for both TinyMCE and CKEditor in the past year-  I knew nothing about plugins for either editor prior to that but with ChatGPT's help I was able to get there in about 90 minutes versus some confusing (to me!) documentation. It was funny because it was ChatGPT creating a plugin to write an article outline USING ChatGPT for one of them 😆

Link to comment
Share on other sites

1 hour ago, Pete said:

I think if you use the dialog and the value saved == the default value, it just shouldn't appear in the hanna code block.

I could probably add an option to support this but I can see it introducing worse issues than it solves. It would make it impossible to save any attribute value where that value has been deliberately set at a value that also happens to be the default. What if the user wants to create a tag where the values should be [[mortgage_calculator default_amount="70000" default_rate="4" default_type="repayment" default_term="25"]]? If all of those attributes get stripped out and you later change the defaults then the tag produces an unintended result.

I think the scenario where you have attributes whose default value you intend to later change is a fairly rare one, and in that scenario you'd be better to not configure a default within the Hanna tag but rather use some other means (e.g. inputfield description or notes text in the dialog) to communicate to the user that there's a fallback value that's used when no value is specified and this fallback is subject to change. That way you can distinguish between when a user has chosen a value or not.

But if you still want the feature and can live with the side-effects then let me know and I'll look at adding it.

  • Like 1
Link to comment
Share on other sites

On 2/9/2024 at 9:47 PM, cb2004 said:

@Pete TinyMCE version is available but i have discovered a few bugs:

 

Neat, I missed that!

@Robin S a very good point and I'm not sure what the solution is to be honest.

EDIT: skip to next post.

A few options:

  1. For some tags the easiest option is not to use the Hanna Code Dialog - maybe we could simply have an option to skip your module being used on a per-tag basis somehow? I've no idea how hard that would be but would solve the problem for this one but still allow it to work for other tags on the same site
  2. In the Hanna Code Dialog have the defaults set as placeholders instead of default values - that way if they aren't populated then they aren't used? I can simply set the defaults in the PHP code then.

I think perhaps option 2 makes the most sense above - if a dialog option has no value entered simply don't add it into the tag markup.

 

EDIT: @Robin S actually the obvious answer is to use parametername__notes and mention the default there and add the default values into the PHP code I think - I'll try that now.

Link to comment
Share on other sites

So I tried this method but it still puts in the parameter if it's empty:

image.png

I think the solution is to use the notes to convey what the default value will be if empty, but also have a way not to add it into the markup if it's empty - perhaps some sort of __omit_empty override, so default_term__omit_empty parameter since we don't want to make assumptions for everyone else using this already?

That way for these specific cases I can also add a note warning them that if it's left empty it will defer to the defaults that can change over time so the content editor has had fair warning.

EDIT again - my brain is not in gear today because I can simply do this myself and check for an empty value 😆 So this is a non-issue now - I can work with this easily by doing:

if(strlen($default_term) === 0) {
  // use the default value in the PHP code
}

And using strlen because the value might actually be a zero of course.

Edit #237: Here's my solution:

image.png

Attributes:

default_amount
default_amount__notes=Leave blank to default to 150000 - default may be changed in future
default_term
default_term__notes=Leave blank to default to 25 years - default may be changed in future
default_type
default_type__type=select
default_type__options=Repayment|Interest Only
default_type__notes=Leave blank to default to Repayment
default_rate
default_rate__notes=Leave blank to default to 4% - default may be changed in future

And defaults are now set in the PHP code, overridden with the HannaCode selections if any values are set

<?php namespace ProcessWire;

$types = ['Repayment' => 'repayment', 'Interest Only' => 'interest']; 

$default_amount = strlen($default_amount) > 0 ? $default_amount : 150000;
$default_term = strlen($default_term) > 0 ? $default_term : 25;
$default_type = strlen($default_type) > 0 ? $types[$default_type] : 'repayment';
$default_rate = strlen($default_rate) > 0 ? $default_rate : 4;

echo $files->render('partials/calculators/mortgage', ['default_amount' => $default_amount, 'default_term' => $default_term, 'default_type' => $default_type, 'default_rate' => $default_rate]);

 

  • Like 1
Link to comment
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
×
×
  • Create New...