I have a content type called article. I have added a field called attribute which can have unlimited values. At present there is an 'Add another term' button present in the add/edit node page to add those extra values. But I want these fields added dynamically and values populated based on the values entered on the body field, i.e. if I had entered #abc, #cdf, #aws on the body field, on blur even, three attribute terms must be generated with values abc, cdf, aws. I have added a javascript code to add the fields, but when saved, only the first value only gets saved.What more should be done or anything is missing? How can this be done. I have done the part of extracting the values. i need to know how form field can be added?
function isevencheck(value) {
if (value%2 == 0)
return true;
else
return false;
}
jQuery.noConflict();
jQuery( document ).ready(function() {
jQuery('#edit-body-und-0-value').blur(function() {
var text = jQuery('#edit-body-und-0-value').val().match(/\#(\w)+/g) ;
$i=0;
contents="";
for (var obj in text) {
if(isevencheck($i)){
cls="draggable odd";
}else{
cls="draggable even";
}
text =text[obj].replace('#', '') ;
contents+='<tr class="'+cls+'"><td class="field-multiple-drag"><a href="#" class="tabledrag-handle" title="Drag to re-order" style=""><div class="handle"> </div></a></td><td><div class="form-item form-type-textfield form-item-field-attribute-und-'+$i+'-value"><input class="text-full form-text" type="text" id="edit-field-attribute-und-'+$i+'-value" name="field_attribute[und]['+$i+'][value]" value="'+text+'" size="60" maxlength="255"></div></td><td class="delta-order tabledrag-hide" style="display: none;"><div class="form-item form-type-select form-item-field-attribute-und-'+$i+'--weight"><label class="element-invisible" for="edit-field-attribute-und-'+$i+'-weight">Weight for row 1 </label><select class="field_attribute-delta-order form-select" id="edit-field-attribute-und-'+$i+'-weight" name="field_attribute[und]['+$i+'][_weight]"><option value="-1">-1</option><option value="0" selected="selected">0</option><option value="1">1</option></select></div></td> </tr>';$i++;
}
jQuery('#field-attribute-values tbody')
.html(contents);
});
});
I think the thing that is left to be done in this is to rebuild form using ajax. How that is to be done?