bernhard

MathParser adds Intelligence to your Number Inputfields

Recommended Posts

Brand new module that I've built because I'm too lazy to always open the calculator when I have to do some calculations (like vat calculations etc):

GiXnx31.gif 

 

It adds some magic to FieldtypeDecimal, FieldtypeFloat and FieldtypeInteger fieldtypes. Of course you can define which fields you want to extend:

sx65CQZ.png

https://github.com/BernhardBaumrock/MathParser

Any ideas or contributions are welcome. What do you think about the name? What do you think about the styling?

  • Like 11
  • Thanks 1

Share this post


Link to post
Share on other sites

Nice one @bernhard,

A couple of thoughts:

  1. Always safer to deal with IDs rather than names. If I have a float field called 'price' and tomorrow I decide to change its name to 'unit_price', MathParser code would not find it (unless of course one is using the autoload feature, in which case it might still throw the warning about field does not exist). The superuser would be forced to change the config.
  2. I've noticed assets (MathParser.js, MathParser.css and math.js) are loaded in all Page Edits, even in ones where it is not required or where there are no compatible fields. Maybe there's no way to get around this?
  3. We started on the premise that we are lazy 😀. So why not take lazy to its logical conclusion? Below, I present lazy max! I've changed the module config textarea inputs to ASM Selects. The descriptions are just dummy text. Only compatible fields (float, integer, decimal [do we have a Fieldtype like this?]) are listed for selection. I don't have a Gitlab account, so I've attached a zip file with the php files to this post.

Having said above. The module did not work for me (even before the changes I made). Shouldn't it be auto-triggering?

Demo

math_parser_asm_inputs.thumb.gif.9a49f00b8a9123037167ed40f6ad31e2.gif

MathParser-kongondo-edits.zip

  • Like 4

Share this post


Link to post
Share on other sites
6 hours ago, kongondo said:

I've noticed assets (MathParser.js, MathParser.css and math.js) are loaded in all Page Edits, even in ones where it is not required or where there are no compatible fields. Maybe there's no way to get around this?

Maybe using the Fieldtype selector in the module autoload setting?? Though I guess that limits the compatibility minimum version.

type=FieldtypeInteger|FiledtypeDecimal

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)
12 hours ago, kongondo said:

decimal [do we have a Fieldtype like this?])

Sure we do, not yet in the core though... 🙂 One can give a thumbs-up over here to support the request of adding it to the core: https://github.com/processwire/processwire-requests/issues/126

EDIT: ot here, but Padloper 2 should utilize FiledtypeDecimal, for example prices should be of this type. There are lots of currencies where a price like 100,000,000.00 is quite possible....

Edited by szabesz
EDIT added
  • Like 2

Share this post


Link to post
Share on other sites

Hi @kongondo thx for your improvements!

On 10/5/2018 at 10:36 PM, kongondo said:

I don't have a Gitlab account

Thx, I've moved the module to github. I'll do that for all my public modules. The workflow is now the same for me (it somehow didn't work before so I stayed with GitLab) and the pw modules directory does also only auto-update versions from github, not gitlab. I've merged your changes.

 

On 10/5/2018 at 10:36 PM, kongondo said:

Having said above. The module did not work for me (even before the changes I made)

You forgot to change one occurance of id/name change. Not sure if/why it really didn't work before the changes. Can't really believe that 😉 Please try version 0.0.2

https://github.com/BernhardBaumrock/MathParser/commit/3b09d501b86df06f4502f8415db9a74d13ac5d23#diff-c4d3faaaa59bb6d7e0d306c2c1312e13L125

  • Like 2

Share this post


Link to post
Share on other sites
11 minutes ago, bernhard said:

I've merged your changes.

Great! I forgot to clean up some copy-paste comments here 🙂

Share this post


Link to post
Share on other sites

Thx, also added a showIf for the exclude config field.

https://github.com/BernhardBaumrock/MathParser/commit/e0f0c27ae07a6d19efb5ba768ae9313babcc873e

On 10/5/2018 at 10:36 PM, kongondo said:

I've noticed assets (MathParser.js, MathParser.css and math.js) are loaded in all Page Edits, even in ones where it is not required or where there are no compatible fields. Maybe there's no way to get around this?

I'm using renderReady - so I'm not sure why fields are loaded?! Any hints? Any experience with this? Working on it 🙂 

Share this post


Link to post
Share on other sites

v0.0.4 fixes the bug mentioned by @kongondo, thank you!

v0.0.5 adds a check to load assets only once

  • Like 2

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.