restrictcontentpro/library

Registration form with <select> element instead of radio buttons?

Closed this issue · 5 comments

Do you guys happen to have any code laying around for rendering subscription levels on the registration form as a select list instead of radio buttons? I'm able to generate the elements just fine, but can't seem to get the right attributes/names/etc. for RCP to recognize it as valid – I get the No available subscription levels for your account. message on the form.

Aaaand I just figured out I'll have to replace register.jsto make this work, so I'm guessing there won't be any drop-in code snippets for this 😕

@tnorthcutt how come you have to replace register.js for it? I'd love to support this properly.

@pippinsplugins because register.js is targeting the input elements specifically, for instance:

// RCP code
var level    = $( '#rcp_subscription_levels input:checked' );

// Modified to work with <select>
var level    = $( '#rcp_subscription_levels option:selected' );

According to the documentation, :checked works for options of select elements too, so maybe this can be generalized to work with either html structure. I'll test and report back.

Ok, this seems to work in rcp_calc_total() so I assume it would as well in the other spots:

var subscription = ( $('#rcp_subscription_levels :checked').length ) ? $('#rcp_subscription_levels :checked').val() : $('input[name="rcp_level"]').val();

In that case and other spots we're checking for :checked and if not present getting the value of the first input[name="rcp_level"], obviously with a <select> list we would no longer have an <input>... but perhaps that's fine since with the select, there's always a :checked element? Although if someone builds a <select> with an empty first option, e.g. "Choose your plan" as an <option>, that wouldn't work. Not sure how to address that situation without some semi-hacky conditionals in the js to see what kind of html we're working with.

So that works if you have one select list... I have three (b/c I'm grouping the subscription levels by "tier", e.g. bronze/silver/gold. Trying to see if I can get it working with that structure as well.