register/registration.php のソースに手を加えない限り、少しトリッキーになります。jqueryに慣れていない場合は、このようにすることができます。登録フォームのどのフィールドをサーバーに伝える、budypress 登録フォームの非表示フィールド ( id "signup_profile_field_ids" ) があり、次のようになります。
<input type="hidden" name="signup_profile_field_ids" id="signup_profile_field_ids" value="5,11,1,10,32">
そのフィールドの値には、登録フォームのフィールド ID が含まれます。
次に、条件付きフィールドを表示する親フィールドを選択する必要があります。親フィールドと条件付きフィールドの ID を知る必要があります
このjqueryコードを使用してください
<script type="text/javascript">
$(function(){
var childs = new Array("Child id 1","Child id 1"); // your child fields ids
var options = new Array("Car","Bike"); // your parent field options, notice option and child number is same, which means, one child for one option
var parent = "Parent Field id"; // place you parent field id
var currentFields = new Array();
currentFields = $("#signup_profile_field_ids").val().split(','); // take all current fields ids in an array
$.each(childs, function(index,value){
$('#field_'+value).parent().hide(); // hide all child fields first
currentFields.splice(currentFields.indexOf(value),1);
});
$("#signup_profile_field_ids").val( currentFields.join() );
$('#field_'+parent).after('<div id="conditional-fields-conteiner></div>"');
$('#field_'+parent).change(function(){
var option = $(this).val();
var appendField = childs[options.indexOf(option)];
var html = $("#field_"+appendField).parent().html();
$('#conditional-fields-conteiner').html(html);
$.each(childs, function(index,value){
currentFields.splice(currentFields.indexOf(value),1);
});
currentField[] = appendField;
$("#signup_profile_field_ids").val( currentFields.join() );
});
});
</script>
これは複雑に思えるかもしれませんが、これが最も簡単な方法です。会員サイトで使用する予定がある場合は、使用しないでください。ユーザーは、html を編集するだけで条件付きフィールドを操作できます。
このためのプラグインもあり、まもなくリリースされます。開発しています
http://rimonhabib.com/coming-up-next-buddypress-nested-conditional-fields/