I have an int cck field that is a select list (thus data is in this field at all times). It's required on the referenced node. Currently I get "Title field is required" because this is set and the title is not. I would assume skip would skip validate but it currently doesn't. Need some help with this one.

CommentFileSizeAuthor
#9 node-widget-series-of-fixes.patch4.01 KBnielsvm

Comments

ademarco’s picture

Status: Active » Closed (fixed)

Fixed in last commit to HEAD: http://drupal.org/cvs?commit=363920

mikeytown2’s picture

Status: Closed (fixed) » Needs work

Still doesn't do it for me. In node_widget.form.inc at the top of the node_widget_node_form_validate() & node_widget_node_form_submit() functions I put this code in to not run the rest of the code if skip is present. This works for me, but is not generalized.

  if ($form['nid']['#post']['field_event_promote'][0]['node_widget']['remove']) {
    return;
  }
crystal_alexandre_froger’s picture

Doesn't work for me either.

Jon_B’s picture

Making @mikeytown2 fix a bit more robust, in /node_widget/includes/node_widget.form.inc, change the function to:

function node_widget_node_form_validate(&$form, &$form_state) {

  foreach (node_widget_get_fields($form) as $field) {
    $node_widget = new node_widget($field, $form, $form_state);
    foreach ($node_widget->get_children() as $delta) {
        if ($form['nid']['#post'][$field['field_name']][$delta]['node_widget']['remove'] != 1 ) {
          $node_widget->validate($delta);
        }
    }
  }
}
arski’s picture

Just got the latest dev and have the same issue. Thanks a lot for fixing!

PS. How about turning "skip" into a js-button that removes that subform? or should i create a separate issue for that :)

Thanks again!

lpedretti’s picture

Another interesting change, node_widget.form.inc , line ~ 140

  $remove_label = ($node->nid) ? t('Delete') : t('Skip');
  $form['remove'] = array(
    '#type' => 'checkbox',
    '#title' => $remove_label,
    '#prefix' => '<div class="node-widget-remove">',
    '#suffix' => '</div>',
    '#default_value' => ($node->nid) ? FALSE : TRUE, // Check the skip link by default, not the delete link on existing relations
    '#weight' => -99,
  );

This makes the skip checkbox default to true when adding empty subforms but not in existing relations subforms.

Crom’s picture

Nice module and great work on patches here. I can confirm that #4 and #6 work - thank you.

It strikes me that the user experience (especially for end users) would be much improved if we could get rid of the 'skip' link entirely. Would the following have merit? A blank sub-form is available underneath any populated sub-forms (as currently). Skip is pre-checked on the blank sub-form and when content is entered into the empty sub-form skip is unchecked by JS. Alternatively, the check is done in PHP and the sub-form either saved or not saved depending upon whether it has any content in it.

I haven't delved into the code but if someone can give me some feedback on the viability of this idea then I might give it a go.

Cheers,
Crom

rustam6996’s picture

Try change file nide_widget.class.inc in function submit($delta)

 /**
   * Validate a node form submission
   */
  function submit($delta) {

    $form = $this->get_form($delta);
    $form_state = $this->get_form_state($delta, TRUE);
    if ($form_state['values']['remove'] && $form_state['values']['nid']) {
      node_delete($form_state['values']['nid']);
    }
   // Added "!$form_state['values']['remove'] &&" for skip empty and remove tagged subnodes
    elseif (!$form_state['values']['remove'] && !$this->is_empty($form, $form_state)) {
      // TODO: Inherit promote and sticky from parent node
      node_form_submit($form, $form_state);
      return $form_state['nid'];
    }
  }

from

elseif (!$this->is_empty($form, $form_state)) {

to

elseif (!$form_state['values']['remove'] && !$this->is_empty($form, $form_state)) {

And all works, best regards from Russia ^)

nielsvm’s picture

StatusFileSize
new4.01 KB

Thanks guys, many of these changes fixed my current project. For those interested, I've incorporated and fully tested the above snippets into one big patch against version 6.x-1.0-beta4 of node_widget (which seems completely unmaintained now), the missing references found in other issues is also in. Please apply the patch from the root of your project, assuming node_widget is inside contrib/:

patch -p1 --dry-run < node-widget-series-of-fixes.patch

Regards,
Niels