Get RowID in editor when displaying file link

Get RowID in editor when displaying file link

joshlevine102joshlevine102 Posts: 44Questions: 16Answers: 2

Hi folks. I was looking at displaying a link or image for an uploaded file, like in the example code given.

            display: function ( id ) {
                return '<img src="'+editor.file( 'images', id ).webPath+'"/>';
            },

Dumb question, is there a way to get the Row_ID or primary key of the row that's being edited at that point in the editor? I guess this would only make sense if only one row was selected, or otherwise it might be a collection. But I was thinking I might be able to do something like this, but I can't figure it out.

editor.field("bis401_sites.Site_ID")
// or
editor.field("DT_RowID")  // or editor.field("id"), or something...

This question has an accepted answers - jump to answer

Answers

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

    Currently you cannot I'm afraid. The reason for this is that if you upload a file in a "create" form there is no primary key value (since the database hasn't created one yet - assuming you have an auto-inc pkey).

    Allan

  • joshlevine102joshlevine102 Posts: 44Questions: 16Answers: 2

    Allan, thanks. OK. I was thinking, if I could get the pkId of the row in the sites table (which has a foreign key into the files table), I could add a delete link which would just set that file id column to be null, as a way of deleting the file, assuming the DbClean might then delete the corresponding file row, since it was now unreferenced. But there may be an easier way to delete files.

  • joshlevine102joshlevine102 Posts: 44Questions: 16Answers: 2

    I guess it makes more sense to just delete the file row, and it should update the foreign key column in the sites table, if the delete action is set properly in the DB.

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

    The update field type has a clearText option which when set will enable a "clear" button which basically will set the database link to null. That way the DbClean can indeed pick it up.

    Regards,
    Allan

  • joshlevine102joshlevine102 Posts: 44Questions: 16Answers: 2

    Allan, thanks. The clearText option was just what I was looking for. Worked perfectly!

This discussion has been closed.