debug
ordre non respect (js compare delatas as string and not numbers) term disparaissant (car delta identiques) translate (entity translate) delete terms Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
461c93d48a
commit
4cf9d7b2c6
@ -246,10 +246,14 @@
|
|||||||
if(delta == -1){
|
if(delta == -1){
|
||||||
track_list_container.append(new_item);
|
track_list_container.append(new_item);
|
||||||
inserted_flag = true;
|
inserted_flag = true;
|
||||||
|
$hiddenInput = $('#'+control_id).parent('.form-item').next('input[type=hidden]');
|
||||||
|
// console.log('$hiddenInput',$hiddenInput);
|
||||||
|
$hiddenInput.val(new_item.index());
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
list_items.each(function(index){
|
list_items.each(function(index){
|
||||||
item_comparing_to = $(this);
|
item_comparing_to = $(this);
|
||||||
if ( delta < item_comparing_to.attr('delta') ) {
|
if ( parseInt(delta) < parseInt(item_comparing_to.attr('delta')) ) {
|
||||||
//Add it here.
|
//Add it here.
|
||||||
item_comparing_to.before(new_item);
|
item_comparing_to.before(new_item);
|
||||||
inserted_flag = true;
|
inserted_flag = true;
|
||||||
@ -262,8 +266,6 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hiddenInput = $('#'+control_id).parent('.form-item').next('input[type=hidden]');
|
|
||||||
$hiddenInput.val(new_item.index());
|
|
||||||
|
|
||||||
track_list_container.sortable('refresh');
|
track_list_container.sortable('refresh');
|
||||||
}
|
}
|
||||||
|
@ -587,75 +587,100 @@ function term_reference_tree_field_widget_form(&$form, &$form_state, $field, $in
|
|||||||
* The validated element.
|
* The validated element.
|
||||||
*/
|
*/
|
||||||
function _term_reference_tree_widget_validate(&$element, &$form_state) {
|
function _term_reference_tree_widget_validate(&$element, &$form_state) {
|
||||||
$items = _term_reference_tree_flatten($element, $form_state);
|
// dsm($element, '$element');
|
||||||
$value = array();
|
// dsm($form_state, '$form_state');
|
||||||
|
# if the field was in the form
|
||||||
|
if(isset($form_state['input'][$element['#field_name']])){
|
||||||
|
|
||||||
|
$items = _term_reference_tree_flatten($element, $form_state);
|
||||||
|
$value = array();
|
||||||
|
|
||||||
if ($element['#max_choices'] != 1) {
|
if ($element['#max_choices'] != 1) {
|
||||||
if(!$element['#track_list_order']){
|
if(!$element['#track_list_order']){
|
||||||
foreach($items as $child) {
|
foreach($items as $child) {
|
||||||
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
||||||
array_push($value, array( $element['#value_key'] => $child['#value']));
|
array_push($value, array( $element['#value_key'] => $child['#value']));
|
||||||
|
|
||||||
// If the element is leaves only and select parents is on, then automatically
|
// If the element is leaves only and select parents is on, then automatically
|
||||||
// add all the parents of each selected value.
|
// add all the parents of each selected value.
|
||||||
if ($element['#select_parents'] && $element['#leaves_only']) {
|
if ($element['#select_parents'] && $element['#leaves_only']) {
|
||||||
foreach($child['#parent_values'] as $parent_tid) {
|
foreach($child['#parent_values'] as $parent_tid) {
|
||||||
if (!in_array(array($element['#value_key'] => $parent_tid), $value)) {
|
if (!in_array(array($element['#value_key'] => $parent_tid), $value)) {
|
||||||
array_push($value, array($element['#value_key'] => $parent_tid));
|
array_push($value, array($element['#value_key'] => $parent_tid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
$selected_terms = array();
|
$selected_terms = array();
|
||||||
foreach($items as $child) {
|
$deltas = array();
|
||||||
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
foreach($items as $child) {
|
||||||
$delta = $form_state['input'][$child['#value'].'-weight'];
|
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
||||||
$selected_terms[$delta] = array($element['#value_key'] => $child['#value']);
|
$selected_terms[] = array(
|
||||||
|
"delta" => $form_state['input'][$child['#value'].'-weight'],
|
||||||
|
"term" => array($element['#value_key'] => $child['#value']),
|
||||||
|
);
|
||||||
|
|
||||||
// If the element is leaves only and select parents is on, then automatically
|
// If the element is leaves only and select parents is on, then automatically
|
||||||
// add all the parents of each selected value.
|
// add all the parents of each selected value.
|
||||||
if ($element['#select_parents'] && $element['#leaves_only']) {
|
if ($element['#select_parents'] && $element['#leaves_only']) {
|
||||||
foreach($child['#parent_values'] as $parent_tid) {
|
foreach($child['#parent_values'] as $parent_tid) {
|
||||||
if (!in_array(array($element['#value_key'] => $parent_tid), $selected_terms)) {
|
if (!in_array(array($element['#value_key'] => $parent_tid), $selected_terms)) {
|
||||||
$delta = $form_state['input'][$parent_tid.'-weight'];
|
$selected_terms[] = array(
|
||||||
$selected_terms[$delta] = array($element['#value_key'] => $parent_tid);
|
"delta" => $form_state['input'][$parent_tid.'-weight'],
|
||||||
}
|
"term" => array($element['#value_key'] => $child['#value']),
|
||||||
}
|
);
|
||||||
}
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// dsm($deltas, '$deltas');
|
||||||
|
// dsm($selected_terms, '$selected_terms before sort');
|
||||||
|
// reorder items
|
||||||
|
usort($selected_terms, function($a, $b){
|
||||||
|
return $a['delta'] > $b['delta'];
|
||||||
|
});
|
||||||
|
dsm($selected_terms, '$selected_terms after sort');
|
||||||
|
|
||||||
|
// record in value
|
||||||
|
foreach ($selected_terms as $selected_term) {
|
||||||
|
$value[] = $selected_term['term'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// reorder items
|
|
||||||
ksort($selected_terms);
|
|
||||||
// record in value
|
|
||||||
foreach ($selected_terms as $delta => $term) {
|
|
||||||
$value[] = $term;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// If it's a tree of radio buttons, they all have the same value, so we can just
|
||||||
|
// grab the value of the first one.
|
||||||
|
if (count($items) > 0) {
|
||||||
|
$child = reset($items);
|
||||||
|
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
||||||
|
array_push($value, array($element['#value_key'] => $child['#value']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if ($element['#required'] && empty($value)) {
|
||||||
}
|
// The title is already check_plained so it's appropriate to use !.
|
||||||
else {
|
form_error($element, t('!name field is required.', array('!name' => $element['#title'])));
|
||||||
// If it's a tree of radio buttons, they all have the same value, so we can just
|
}
|
||||||
// grab the value of the first one.
|
|
||||||
if (count($items) > 0) {
|
form_set_value($element, $value, $form_state);
|
||||||
$child = reset($items);
|
// dsm($element, '$element afetr form_set_value');
|
||||||
if (array_key_exists('#value', $child) && $child['#value'] !== 0) {
|
return $element;
|
||||||
array_push($value, array($element['#value_key'] => $child['#value']));
|
}else{
|
||||||
}
|
# if the field was not in the form
|
||||||
}
|
form_set_value($element, $element['#default_value'], $form_state);
|
||||||
}
|
// dsm($element, '$element afetr form_set_value');
|
||||||
|
return $element;
|
||||||
if ($element['#required'] && empty($value)) {
|
|
||||||
// The title is already check_plained so it's appropriate to use !.
|
}
|
||||||
form_error($element, t('!name field is required.', array('!name' => $element['#title'])));
|
|
||||||
}
|
|
||||||
|
|
||||||
form_set_value($element, $value, $form_state);
|
|
||||||
return $element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user