SQL Custom Field Default Value and No Value when field is optional Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Post Reply
Amongthegums
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Wed Mar 04, 2015 6:22 am

SQL Custom Field Default Value and No Value when field is optional

Post by Amongthegums » Mon Feb 06, 2023 11:04 pm

Following the advice in the docs (https://docs.joomla.org/SQL_form_field_type) I have hit a brick wall trying to assign a default value. It seems no matter what I enter into the default field I get a fatal error on save.

My SQL follows the format "SELECT id AS value, name AS text FROM some_table"

A valid value, for example 1, is entered as 1 into the default field and I hit save to get Invalid Default Value Error!(?)

What is the correct format for entering the default value?

Second, is there any way to force a NULL or blank value for optional SQL fields, i.e. no selection.

Thanks in advance.
Last edited by imanickam on Thu Feb 09, 2023 3:57 am, edited 1 time in total.
Reason: Moved topic » from General Questions/New to Joomla! 3.x to Joomla! 4.x Coding

Amongthegums
Joomla! Intern
Joomla! Intern
Posts: 87
Joined: Wed Mar 04, 2015 6:22 am

Re: SQL Custom Field Default Value and No Value when field is optional

Post by Amongthegums » Thu Feb 09, 2023 3:47 am

For what it's worth I fudged it with SQL

SELECT 0 AS value, '- Select a delegate -' AS text
UNION
SELECT #_users.id AS value, #_users.name AS text
FROM
#_users

This way value - "Select a delegate" is the default choice on new records. That'll work for me.


Post Reply

Return to “Joomla! 4.x Coding”