fomantic / Fomantic-UI

Fomantic-UI is the official community fork of Semantic-UI
https://fomantic-ui.com
MIT License
3.58k stars 333 forks source link

[form] unable to set default prompt for custom function #2976

Open alvarolm opened 10 months ago

alvarolm commented 10 months ago

Bug Report

when setting the default prompt (function) for a custom rule it triggers the error: Uncaught TypeError: prompt.search is not a function https://github.com/fomantic/Fomantic-UI/blob/develop/src/definitions/behaviors/form.js#L564

Steps to reproduce

set this defaults before instanciating a form

$.fn.form.settings.rules.mindate = function(value) { return false; };

$.fn.form.settings.prompt.mindate = function(v) { return "custom prompt working!" }

Expected result

no error

Actual result

Uncaught TypeError: prompt.search is not a function

Testcase

https://jsfiddle.net/0tsurydw/2/

Screenshot (if possible)

image

Version

2.9.3

lubber-de commented 10 months ago

The custom prompt has to be provided at type declaration https://fomantic-ui.com/behaviors/form.html#customizing-prompts

rules: [
          {
            type   : 'myrule',
            prompt : function() {
                            return "custom prompt working!"
                        }
          }
        ]

See https://jsfiddle.net/lubber/5vre3aLo/3/

lubber-de commented 10 months ago

Your other approach works too, but only if the central value is type of string (this is something we could improve to also accept functions here)

$.fn.form.settings.prompt.myrule = "custom prompt working!";

https://jsfiddle.net/lubber/5vre3aLo/7/

alvarolm commented 10 months ago

understood, in my case the prompt is always generated so it needs to be function, for now it seems i will have to provide it each time with a type declaration

may be in the future I'll implement pr, thanks !

lubber-de commented 10 months ago

may be in the future I'll implement pr, thanks !

I just did by #2977 😉

alvarolm commented 10 months ago

thank you so much !