1. Fabrik 3.8.1 has been released. It is mostly bug fixes and feature enhancements, but does include two new plugins (push notifications, and the sequence element). As usual we strongly recommend testing the new release on a sandbox if your application is mission critical, and always do an Akeeba backup before updating.
    Dismiss Notice

Isuniquevalue with 2 conditions in 2 tables

Discussion in 'Community' started by albertotactik, Mar 9, 2018.

  1. albertotactik

    albertotactik Member

    Level: Community
    good...
    I'll check the file you sent me ... thanks.
    I write the fields.xml code to make sure I made the change.
    you already tell me ... if the fields.xml file is now correctly
    attached file with extension .xml.txt

    once, that these files are fine ...
    I understand that only language translation will be missing ...
    and these files will be available for future updates ...
    that is ... there will be an official "areuniquevalues" validation with the option of "condition" ...
    is it like that?

    Thanks again
     

    Attached Files:

  2. Sophist

    Sophist Well-Known Member

    Level: Community
    There is an "s" missing from "areuniquevalues-validation_condition".

    Once you have made it work you need to create a Pull Request on Github with all the files you have changed.

    When you have completed this, then at some point Hugh will review it and if he is happy with the code it will be merged into Fabrik. Then when the Fabrik 3.8.2 or 3.9 version of areuniquevalues is released or when you "update from Github", your PR will be included.
     
  3. albertotactik

    albertotactik Member

    Level: Community
    Very good ...
    It seems ... that the new code "areuniquevalues" is going very well ... thank you very much for helping me to add the section "condition" in the validation "areuniquevalues":):)
    With this "condition" I think I have a small problem and doubt ...:(
    I explain:
    In a table "expediente" I make a condition in a validation areuniquevalues ...
    This condition points to another "gphabitatge" table ...
    if ('{gphabitatge___gp_hab_tipusinmoble}' == 'habitatge')
    {
    return true;
    }
    else {
    return false;
    }


    I note that if the condition contains the elements of the same "expediente" table ... yes it works correctly
    But if I do the condition with elements of the habitatge table ... it does not work ...
    Is there a way to fix this problem ... ??
    I feel like I have traveled a road ... and I would like to reach the end ...:rolleyes:
    If you need some more explicit example or detail ... tell me.
    Thanks again
     
  4. Sophist

    Sophist Well-Known Member

    Level: Community
    You can only use placeholders which are in your form.

    I you liked my help, please create the Pull Request with your new code so that others can benefit.
     
  5. albertotactik

    albertotactik Member

    Level: Community
    You can only use placeholders which are in your form.
    I imagined it to be like that ... thanks

    I you liked my help, please create the Pull Request with your new code so that others can benefit
    I am sorry but I do not understand...
    I like all your answers.

    what is pull request?

    and when you speak of new code ...
    Do you think you could insert some php code ... for the condition of another table?

    if so ... should the code be inserted in the form?
    if possible ... I try ...
    thanks for your help!
     
  6. Sophist

    Sophist Well-Known Member

    Level: Community
    As I said in post #6 of this thread, if you want all your changes to areuniquevalues to survive a fabrik upgrade or an update from Github you need to create a Github PR or Pull Request to submit your new code to Fabrikar for inclusion in Fabrik.

    See the Wiki entries for Github to see how this works: http://fabrikar.com/forums/index.php?wiki/github-hints-and-tips/
     
  7. albertotactik

    albertotactik Member

    Level: Community
    Yes, I have it pending ...
    before I want to finish doing all the translations ... it will take me a while ...
    As soon as I have it ... I try to create a PR github.

    respect that a validation condition ... make reference to another table or form ... is it possible?
    thanks!
     
  8. Sophist

    Sophist Well-Known Member

    Level: Community
    Validation condition runs some php code. You can do anything you want to in that php code - so long as it returns true or false.

    But if you want to use placeholders, then they have to be available in the groups that are in the form. So if you want to refer to a placeholder from one table in an element from another table, you can only do this if the tables are joined in the List / Data / Joins settings.

    Alternatively you could do a database select inside the condition php and test for anything you might want to.
     
    Last edited: Mar 14, 2018
  9. albertotactik

    albertotactik Member

    Level: Community
    hello!
    Validation condition runs some php code. You can do anything you want to in that php code - so long as it returns true or false.
    I understand that you can include php code that returns true and false ... within the condition ...
    Is that so?
    This code that I show ... would be valid ?? I have tried several ways and it does not work for me.

    if gphabitatge.gp_hab_tipusinmoble == 'habitatge'
    {
    return true;
    }
    else {
    return false;
    }

    But if you want to use placeholders, then they have to be available in the groups that are in the form. So if you want to refer to a placeholder from one table in an element from another table, you can only do this if the tables are joined in the List / Data / Joins settings.
    Ok ... I rule it out.

    Alternatively you could do a database select inside the condition php and test for anything you might want to.
    I do not just understand ... Is there an example in the wiki?
    Thank you for your patience ... I guess you must be tired of this topic ...
    It's exhausting me ...
    Thanks again.
     
  10. Sophist

    Sophist Well-Known Member

    Level: Community
    Placeholders are '{element_name}'.
    Code (Text):
    if gphabitatge.gp_hab_tipusinmoble == 'habitatge'
    is not a valid statement.

    But your php code could e.g. make database calls, web service calls, etc. limited only by your imagination and your programming skills.
     
    albertotactik likes this.
  11. Sophist

    Sophist Well-Known Member

    Level: Community
    The difficulty I have is that I cannot visualise what you are trying to achieve. As I said before, if you want to access the values in another table it needs to be joined. But I cannot visualise what you are trying to achieve and so cannot help you with the detail.
     
  12. albertotactik

    albertotactik Member

    Level: Community
    Good...
    I think in some way or another and with your help I'll get it.
    I will review thoroughly and on the forum Fabrik wiki information on
    The valid code declarations in Fabrik to enter PHP code, using the PHP plugin of the form.
    http://fabrikar.com/forums/index.php?wiki/php-form-plugin/
    Thank you....
     
  13. albertotactik

    albertotactik Member

    Level: Community
    I will try to explain the problem that takes me around 10 days... through an image and text. I hope you can understand... if you do not understand tell me.
    I have a "expedient" form and it contains 2 databasejoin elements.
    1st element is called Gp_exp_sol and points to a table "gpsolicitant" using ID
    2nd. Item is called Gp_exp_hab and points to a "gphabitatge" table using ID​
    The user selects a name "Albert" in the first element and a "Habitatge" status in the second element.
    Once selected... This data is recorded in a table "Gpexpedient"
    by validating... isuniquevalue and Areuniquevalues tried the following...
    You can only record the data "Albert and Habitatge" in the file table if Albert does not already have a habitatge...
    But you have to keep in mind that Albert:
    You can have 1 Habitatge and 2 aparcament​
    Once last one week and if Albert returns to request a "habitatge" The validation of the form, will not allow it, because it already has 1 habitatge... but can ask for a 3 aparcament... happening to have:

    1 Habitatge + 1 Aparcament + 1 aparcament + 1aparcament.​

    Have I explained a little better??
    A thousand thanks for the patience and attention.
    attached image explain!;)
    upload_2018-3-15_18-25-39.png
     

    Attached Files:

  14. Sophist

    Sophist Well-Known Member

    Level: Community
    OK - we still have a problem - which is that areuniquevalues needs to have a set of fields to be unique in the table, and you don't have a field containing just habitatge / aparcament.

    So you need to create a hidden calc element that contains that (from the {expedient___gp_exp_hab} field).
    PHP:
    return explode(' | ', '{expedient___gp_exp_hab}')[0];
    • Explode splits the string into an array containing the original columns.
    • [0] selects the first element of this array
    So now you need to set the areuniquevalues on the calc element and / or the expendient___gp_exp_sol element with the condition:
    PHP:
    if ('{expedient___calc_name}' == 'habitatge')
    {
        return true;
    }
    return false;
    Hope this works for you.
     
    albertotactik likes this.
  15. albertotactik

    albertotactik Member

    Level: Community
    Good Morning?
    New item for me ... I researched in the wiki ... and it seems very interesting.
    However ... I followed your instructions, even the most basic possible ...
    upload_2018-3-17_7-44-46.png
    To be able to visualize the value that it returns ... and it only shows the label ...

    I have not seen, where I'm making the mistake ...

    Once, solve this ... I will proceed to make your instructions.
    I understand that with your indications ... you should take in the field you define in [x] in this case it would be:

    return ('|', '{gpexpedient ___ gp_exp_hab}') [5];
    Or would it be this?

    return explode ('|', '{expedient ___ gp_exp_hab}') [5];

    Attached image where the element and the table gpexpedient are displayed ...

    I have tried with
    return explode and only with return ...

    Thank you very much for providing me with new ideas and solutions ...

    upload_2018-3-17_7-45-9.png
     
  16. albertotactik

    albertotactik Member

    Level: Community
  17. Sophist

    Sophist Well-Known Member

    Level: Community
    1. Campos ajax a revisar should not have "return" in it.
    2. Why have you used [5] rather than [0]?
     
  18. albertotactik

    albertotactik Member

    Level: Community
    1) good...
    I have tried several options ...
    even ... testing with other elements ...
    upload_2018-3-17_9-52-24.png
    and it returns only the "label"
    upload_2018-3-17_9-51-36.png


    I understand that I should extract the value of the table from the table ... is that so?
    if so ... it would be wonderful.

    2. Why have you used [5] rather than [0]?

    I thought that if I indicate [5] I would take the value of the fifth column "gp_exp_hab"
    [​IMG]
    thanks for your help!
     

    Attached Files:

  19. Sophist

    Sophist Well-Known Member

    Level: Community
    What is the point of me writing code for you and saying use [0] if you disregard that and make me have to spend even more time explaining.

    {gpexpedient ___ gp_exp_hab} is an SQL CONCAT of three columns using " | " as a separator.

    The explode using " | " separates these back into the three parts. [0] is the first of these parts which is gp_hab_tipusinmoble. And this is what we want to test for "habitatge".

    It is NOT "returning only the label". The label is ... well ... the label which is displayed regardless of what is returned. It is returning "" because [5] is empty.

    I am afraid I have done as much as I can for you with this.
     
  20. Sophist

    Sophist Well-Known Member

    Level: Community
    P.S. Please don't forget that if you want your changes to areuniquevalues to stick when you do an upgrade of fabrik you will need to create a Pull Request.
     

Share This Page