MySQL: Foreign key constraint on composite key with the referenced table a function of a constituent column of the key
Maybe it's not exactly what you expected but you can try such table structure:

CREATE TABLE customFields (
    id INT UNSIGNED NOT NULL
    ,type VARCHAR(15) NOT NULL -- it would be better to use bit
    ,foreignIdMultipleChoice INT NULL    
    ,foreignIdText INT NULL
    ,foreignId INT AS (IFNULL(foreignIdMultipleChoice, foreignIdText))
    ,CONSTRAINT FK_foreignIdMultipleChoice FOREIGN KEY (foreignIdMultipleChoice)
        REFERENCES customFieldsMultipleChoice(id)
    ,CONSTRAINT FK_foreignIdText FOREIGN KEY (foreignIdText)
        REFERENCES customFieldsText(id)
    )


You will need to insert foreignId value into one of these columns (foreignIdMultipleChoice or foreignIdText) depending on the field source. If you are on latest version of MySQL you can add check constraint to avoid issues when both of these columns are nulls or both of them are not null simultaneously. Something like this: 

,CONSTRAINT `foreignId_check` CHECK ((foreignIdMultipleChoice &gt; 0 AND foreignIdText IS NULL) 
                                      OR (foreignIdMultipleChoice IS NULL AND foreignIdText &gt; 0))