1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Problem with Element Dropdown, same values different labels

Discussion in 'Community' started by marioms, Oct 22, 2021.

  1. marioms

    marioms Member

    Level: Community
    Hello there!

    I am having trouble making this work. So I have a billing system that calculates a total amount of money based on this:

    [​IMG]

    And a few of the contractors have the same rate per hour:

    [​IMG]

    This is how it is being displayed on the form:

    [​IMG]

    And once I submit, I can see the newly created entry on the list but the contractor is wrong, it just selects a random contractor with the same value:

    [​IMG]

    Is there a way to make it show the correct contractor? (i.e the one I selected on the form, even if they have the same values?) if not, what kind of solution I can apply?

    Also, when I am back to the form for edit, it shows a totally different contractor again (but one with the same value as the selected one). So I am not sure how to fix this issue.

    Thank you in advance!
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    You can't have the same value for different labels. The value is stored in the DB, how should anybody know which of the different labels belongs to it?
    You can use an additional table/list with e.g.
    id, rate, contractor
    and a databasejoin element pointing to this table (with value=id[recommended]).

    You can then fetch the rate from the database.
     
    juuser likes this.
  3. juuser

    juuser Well-Known Member

    Level: Community
    You've got the "value" concept totally wrong. If you use dropdown element, "value" should be unique like "contractor_name" or numeric like 1, 2, 3 etc.

    And even better to use @troester's suggestion to have a separate list and dbjoin element for contractors.
     
  4. marioms

    marioms Member

    Level: Community
    Thank you so much, that makes sense, I will make the additional table and the databasejoin element :)
     
  5. marioms

    marioms Member

    Level: Community
    You are right, I totally got it wrong, I guess a need a coffee because my brain is not working properly this morning :p
     
    juuser likes this.
  6. marioms

    marioms Member

    Level: Community
    Good morning!

    I'm back again. I have done the new table with the ID, Contractor name and rate:

    [​IMG]

    And I created the new databasejoin element:

    [​IMG]
    I also updated the formula I have for calculating the rate * hours:

    [​IMG]

    So it is obviously not working at the moment because the new element points at the id of the contractor (with the name as a label) and not at the rate to make the calculation:

    [​IMG]
    So I would like to know how to fetch the rate so the calculation works. Is that something I need to add to the databasejoin element itself? to the formula?

    Thank you in advance.
     
  7. juuser

    juuser Well-Known Member

    Level: Community
    In calc element you can get the hourly rate something like:
    Code (Text):
    $contractor = '{j32db_scitech___Contractor_raw}';

    $mydb = JFactory::getDBO();
    $mydb->setQuery("SELECT rate FROM j32db_contractors WHERE id = ".$mydb->Quote($contractor));
    $hourlyrate = $mydb->loadResult();
    Make sure you change the "rate" in the query to your real rate element name if it's something different.
     
    marioms likes this.
  8. marioms

    marioms Member

    Level: Community

    Thank you so much Juuser, it works fine! :)
     

Share This Page