CoreBOSBB
Do validations only allow true or false - Printable Version

+- CoreBOSBB (https://discussions.corebos.org)
+-- Forum: Development (https://discussions.corebos.org/forumdisplay.php?fid=18)
+--- Forum: coreBOS Development (https://discussions.corebos.org/forumdisplay.php?fid=4)
+--- Thread: Do validations only allow true or false (/showthread.php?tid=1882)

Pages: 1 2


Do validations only allow true or false - Guido1982 - 08-04-2020

I was asked to do a validation where the salesorder shipping address needs to match the account shipping address. Now that's easy enough, but I was also asked to provide the option to overwrite the currect salesorder address with the address from the account when there is no match. Do we have some option to fire a custom function when a validation fails or is it just true of false? And if it is, would it be a good idea to allow custom 'ontrue' and 'onfalse' handlers? I could work on that.


RE: Do validations only allow true or false - joebordes - 08-07-2020

I had a quick look which escalated into a little over half an hour to implement this change

https://github.com/tsolucio/corebos/commit/4b942d0b3686b8f20e9d2567bb5251dd653bcbe0

that permits us to use the same functionality we have in the custom file validations, where you can return CONFIRM and FUNCTION


Code:
<map>

  <originmodule>
    <originname>Accounts</originname>
  </originmodule>
  <fields>
    <field>
      <fieldname>accountname</fieldname>
      <validations>
        <validation>
          <rule>contains</rule>
          <restrictions>
          <restriction>mex</restriction>
          </restrictions>
<message>%%%FUNCTION%%%yourfunction%%%PARAMS%%%{field},lbl</message>
        </validation>
      </validations>
    </field>
  </fields>
</map>

your custom function has to have this profile:

(edit_type, formName, action, callback, params)

I see that FUNCTION is not documented here:

https://corebos.com/documentation/doku.php?id=en:devel:corebos_validation

it should be


RE: Do validations only allow true or false - joebordes - 08-07-2020

there is an example here: http://blog.corebos.org/blog/developerblock

give it a try and let me know how it goes


RE: Do validations only allow true or false - Guido1982 - 08-10-2020

Very nice, let me try and figure this out.


RE: Do validations only allow true or false - Guido1982 - 08-10-2020

(08-07-2020, 01:34 AM)joebordes Wrote: there is an example here:  http://blog.corebos.org/blog/developerblock

give it a try and let me know how it goes

About the class code example in the blog, you left the line
PHP Code:
$smarty $this->getViewer(); 
in there.


RE: Do validations only allow true or false - joebordes - 08-10-2020

I think that is intentional to show readers that they have access to that object without creating it again (less memory and setup overhead)


RE: Do validations only allow true or false - Guido1982 - 08-10-2020

Ah, thought it didn't live on the parent but that's where it comes from then

(08-07-2020, 01:34 AM)joebordes Wrote: there is an example here:  http://blog.corebos.org/blog/developerblock

give it a try and let me know how it goes

Can't get this to work. I've tried logging my 'process' function to the fatal log, but it never seems to be called. Neither does it cause an error. I created the business action for the developerblock but it doesn't seem to do anything.


RE: Do validations only allow true or false - joebordes - 08-10-2020

I tried it. can you share some maps to see what you have done?


RE: Do validations only allow true or false - joebordes - 08-10-2020

you just need to create a JS function and return the message in the indicated format


RE: Do validations only allow true or false - Guido1982 - 08-10-2020

I'm not sure I understood the instructions correctly then. Judging by the blogpost I thought I didn't have to create a map. I thought a developerblock of type 'presave' would just do the work, returning the name of the JS function to be executed along with parameters.