• Resolved Goran

    (@hrvan)


    Hi there.
    I’m using radio button DS to get data from database. I managed to get it working and I have only one value inside. I wonder how can I make that radio button to be checked on load?

Viewing 15 replies - 1 through 15 (of 39 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The process is really simple. I will try to describe it with an example.

    Assuming your datasource is returning the following pairs of data for the choices:

    First Choice:
    – Value: 31
    – Text: First item

    Second Choice:
    – Value: 65
    – Text: Second item

    Third Choice:
    – Value: 89
    – Text: Third item

    And you want tick the second choice by default (when the data be loaded).

    In this case you only should enter the value corresponding to the second choice: 65 through the attribute: “Select by default” in the properties of the “Radio Button DS” field, and that’s all.

    Best regards.

    Thread Starter Goran

    (@hrvan)

    Hi.
    I have only one choice. The value is changeable. It depends from the package to package so I can’t use value as target. I should be able to target the first (and only) choice in some other way. How?

    Plugin Author codepeople

    (@codepeople)

    Hello @hrvan,

    The process is very simple. Assuming the field is the fieldname1, you simply should insert a “HTML Content” field in the form with the following piece of code as its content:

    
    <script>
    jQuery(document).on('change', '[id*="fieldname1_"]', function(){
    jQuery('[id*="fieldname1_"]:eq(0)').prop('checked', true);
    });
    </script>
    

    and that’s all.
    Best regards.

    Thread Starter Goran

    (@hrvan)

    Thanks indeed that is working.
    Is it possible to input simple text inside Column for texts:
    Let’s assume I want to put some title for radio button like Section 1?

    Plugin Author codepeople

    (@codepeople)

    Hello @hrvan,

    The process depends of datasource used to populate the field. For example, assuming you are using a database as datasource, and the table’s name is: my_table, the column’s name for values: column_a, and you want populate the text of choices with the text: ‘this text’, the query would be similar to:

    SELECT column_a as value, 'this text' as text FROM my_table

    I’m sorry, but this question is not specific to our plugin, these are general knowledge about SQL. If you need additional support implementing your specific project, I can offer you a custom coding service from my private website:

    https://cff.dwbooster.com/customization

    The support service does not cover the implementation of the users’ projects.

    Best regards.

    Thread Starter Goran

    (@hrvan)

    I’m not sure I understand you correctly. How do you mean it’s not specific for the plugin to change the Choices text of the radio button?
    Maybe you didn’t understand me.
    Normal radio button has a place to put text and a place to put value.
    Radio button DS is not giving me solution to change the text. And I cannot call it from database cause there is no text there.
    I’m using database as datasource and my table is wp_postmeta.
    Since I’m importing things from ACF fields I have meta_key and meta_value.
    I need and am getting meta_value as Columns for value, but I want to put inside the Radio button DS Columns for text some title like in normal radio button.
    Can I change meta_key to something like: ‘this text’?
    The querry would then be SELECT meta_key as value, ‘this text’ as text FROM wp_postmeta?!

    Plugin Author codepeople

    (@codepeople)

    Hello @hrvan,

    Exactly, the question is about SQL queries, and not the plugin, in the “SELECT” queries if you want the resulting rows include a specif text, instead to use the column’s name, use directly the text, similar to:

    SELECT column_name as value, 'this text' as text FROM table_name

    In the previous query the values of choices in the “Radio Button DS” field would be values into the column_name column, but the texts of the choices would be: this text

    Best regards.

    Thread Starter Goran

    (@hrvan)

    I’m importing this query in Select by default part or also in HTML Content?

    Plugin Author codepeople

    (@codepeople)

    Hello @hrvan,

    Not exactly. Please, look the screenshot visiting the following:

    https://wordpress.dwbooster.com/customdownloads/2018/01/19/screenshot_ds.png

    Pay attention to the properties of the “DS” fields, if you need to enter a custom query, as in this case, you should tick the “Custom Query” option, and enter the query through the “Type the query” attribute.

    Best regards.

    Thread Starter Goran

    (@hrvan)

    Hello.
    Sorry, but for some reason I was not able to login, and reset of password didn’t work.
    Now I’m back…
    I did what You said.
    I have a problem with configuring this.
    OK.
    This is what I did:
    On radio button DS in Custom Query I’ve added: SELECT meta_id as value, ‘Viza’ as text FROM wp_postmeta
    In Query Structure I have:
    Columns for Values: meta_value
    Column for texts: meta_key
    Table name: {wpdb.postmeta}
    Condition: meta_key=’viza_1′ AND post_id=<%fieldname2%>
    When I check Query Structure I get the radio button but with acf id as title, and if I check Custom Query then I get continuos checkboxes with value Viza…
    Where am I doing wrong?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    You are not defining the “WHERE” clause in the custom query. The equivalent to the described query is:

    
    SELECT meta_value as value, 'Viza' as text FROM {wpdb.postmeta} WHERE meta_key='viza_1' AND post_id=<%fieldname2%>
    

    and that’s all.
    Best regards.

    Thread Starter Goran

    (@hrvan)

    Thanks a million!
    That’s working!

    Thread Starter Goran

    (@hrvan)

    Hm,
    now I have the same problem with dropdown DS where i’m pulling data through URL and use this code:
    [CP_CALCULATED_FIELDS_VAR name=”nadoplata1″]

    <SCRIPT>
    cpcff_default = { 1 : {} };
    cpcff_default[1][ 'fieldname172' ] = nadoplata1;
    </SCRIPT>

    If I don’t add anything in Custom Querry it works, but if I add this:
    SELECT meta_value as value, ‘Nadoplata za jednokrevetnu sobu 1′ as text FROM {wpdb.postmeta} WHERE meta_key=’nadoplata_1’ AND post_id=<%fieldname2%> it doesn’t

    Plugin Author codepeople

    (@codepeople)

    Hello @hrvan,

    The field in the new form seems be the fieldname172, so, the query would be:

    
    SELECT meta_value as value, 'Nadoplata za jednokrevetnu sobu 1' as text FROM {wpdb.postmeta} WHERE meta_key='nadoplata_1' AND post_id=<%fieldname172%> 
    

    I’m sorry, but the support service does not cover the implementation of the users’ projects. If you need additional help implementing your project, I can offer you a custom coding service, from my private website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter Goran

    (@hrvan)

    I’m sorry, maybe I didn’t explain it good. It’s my fault.
    The field is not dropdown DS it’s checkbox DS.
    Ive tryed the URL on Calculated field and it works. But what I need is to get the value from URL to checkbox cause the service is optional.
    I understand this goes beyond your services but can you push me a little forward cause I’m stuck and can’t find the solution even though I know it’s not so hard.
    I need to have the title I can change, and it has to be checkbox.
    Since I know the code for Calculated field is it possible to get the value of it to checkbox or radio button? I think I saw that tutorial but cannot find it…

Viewing 15 replies - 1 through 15 (of 39 total)

The topic ‘Radio button DS’ is closed to new replies.