Updating other fields in Database - based on select

Updating other fields in Database - based on select

ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

Hi Everyone

I've just used the bar bones of the editor to update tables I need to edit and its working great (using in-line editing). However, I'm not sure how to move forward on this. I have a screen that list of samples taken during a specific inspection. showing 1) Where it was taken 2) the item it was taken from (window, wall, etc) 3) it's Sample number.... in addition I'm displaying 2 additional "Results" selections - the "Result" and "Recommended Action". I can update both these fields no problem and the data base it updating correctly. My problem is,,,, When I select the "Result" - I need 2 things to happen.

1) Set another field called "SampleType" - this is a value based from 0 to 3 depending on which "Result" is selected - so basically I need to use a select/case check the "result"
2) once Sample Type is done I need to do some maths and update a field called "totalRisk" using the value in SampleType and three other fields.

The above is easy in MS Access. I'm sure it's sometihing I need to do on an **event ** such as **change ** on the "Result" select- but I'm not sure how to move forward on this.

If anyone has an idea I would greatly appreciate it.

Thank you in advance for any guidance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Sounds like a perfect use case for the dependent() method. With that a callback function will be triggered when a field's value is changed allowing you to set other field's values, or otherwise change the form.

    This example just controls field visibility, but it shows the basics of how it can be used.

    Allan

  • ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

    Thank you Allan I'll have a look

  • ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

    THanks for your help Allan - getting there :) But I have a couple of questions....

    I only want to use the "inline" functionality of the Editor - so I've been able to remove the New, Delete, Create buttons no problem - which is fine...

    the AJAX call - includes a large number of fields that I need the data for BUT does not need displaying/setting up on the Editor "form" - and the only way I can set a value is with the field on the editor for so I can use something like this:

    editor.dependent( 'tblASBassets.asbestosFound', function ( val ) {
    if(val === 'NAD') {
    editor.field('tblASBassets.totalScore').val(0) ;
    editor.field('tblASBassets.MAscore').val(0) ;
    editor.field('tblASBassets.PAscore').val(0) ;
    editor.field('tblASBassets.MAS1').val(0) ;
    editor.field('tblASBassets.MAS2').val(0) ;
    editor.field('tblASBassets.MAS3').val(0) ;
    editor.field('tblASBassets.MAS4').val(0) ;
    editor.field('tblASBassets.PAS1').val(0) ;
    editor.field('tblASBassets.PAS2').val(0) ;
    editor.field('tblASBassets.PAS3').val(0) ;
    editor.field('tblASBassets.PAS4').val(0) ;
    }
    } );

    If I have to set up say 25 fields on the editor form then be it... but would prefer to find a cleaner solution.

    Thank you in advance of any help given.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓
    editor.val( {
      "tblASBassets.totalScore": 0,
      "tblASBassets.MAscore": 0
      ...
    } );
    

    would be one option. Or if you have an array of the field names you want to set to 0 you could loop over that and set each individually to 0.

    Allan

  • ShaneBrennanShaneBrennan Posts: 49Questions: 18Answers: 1

    Thank ypu very much Allan - working a treat!!

This discussion has been closed.