Also auf meinem benutzerdefinierten Modul, das ich erstellt habe, gibt es eine Absenden-Schaltfläche (Formular in PHP definiert), aber es ruft bereits eine Aktion, ruft eine Rückruffunktion, um die Anzeige einiger Informationen auszulösen in Bezug auf einen bestimmten Barcode direkt darunter.Automatisches Scrollen beim Klicken auf meine Senden-Schaltfläche
Alles, was ich tun möchte, ist etwas Code hinzufügen, die meine Submit-Taste auch ein automatisches Scrollen nach unten ohne einen Link/Anker auslösen kann (weil ich die SUBMIT BUTTON, um diese Aktion, nicht einen anderen Link erwerben möchten) Benutzer muss nicht nach unten scrollen, um die Informationen anzuzeigen.
Der Grund, warum ich die Link/Anker-Option vermeide, ist, weil ich einfach keine separate Entität haben möchte, die angeklickt werden muss, um nach unten zu scrollen. Ich möchte, dass die Scroll-Datei korrekt ausgeführt wird, wenn ich auf den Absenden-Button klicke. Es sei denn, ein Link kann mit einem Button kombiniert werden? Vielen Dank!
Meine PHP Submit-Button Form:
//submit button that uses ajax (to display whats in callback)
$form['submit_button'] = array(
'#type'=> 'submit',
'#value'=> t('Submit'),
'#ajax' => array(//no need to refresh the page bc ajax
'callback' => '_ibbr_inv_after_callback', //callback
),
'#suffix' => "<div id='after_div'><br></div>
<div id='after_status'></div>",
);
return $form;
Meine PHP Callback-Funktion:
//function for submit button callback
function _ibbr_inv_after_callback($form, $form_state) {
$selector = '#after_div';
$commands = array();
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->propertyCondition('type', 'eq')
->propertyCondition('title', $form_state['input']['barcode'])
->propertyCondition('status', 1)
->range(0,1)
->execute();
//If this barcode is found in database
if (!empty($entities['node'])) {
$node = node_load(array_shift(array_keys($entities['node'])));
//Load fields from returned equipment item
$room = taxonomy_term_load($node->field_eq_room['und'][0]['tid']);
$desc = $node->field_eq_description['und'][0]['value'];
$manu = $node->field_eq_mfr['und'][0]['value'];
$model = $node->field_eq_modelno['und'][0]['value'];
$serial = $node->field_eq_serial['und'][0]['value'];
//displaying all the components of the specific barcode
$info = "<div id='after_div'><b>Title</b>: $node->title<br>
<b>Description</b>: $desc<br>
<b>Manufacturer</b>: $manu<br>
<b>Room</b>: $room->name<br>
<b>Model Number:</b> $model<br>
<b>Serial Number:</b> $serial<br></div>";
//Displaying the Confirm and Flag buttons
$commands[] = ajax_command_replace($selector, $info);
$commands[] = ajax_command_replace("#after_status", "<div id='after_status'> <button id = 'confirm' type = 'submit' name = 'Confirm' value = 'Confirm'> Confirm</button><button id = 'Flag' type = 'submit' name = 'flag' value = 'flag'>Flag </button> </div>");
//$commands[] = ajax_command_invoke("#after_div", 'animate', array("{scrollTop: top}",1000));
//If this barcode is not found in the database
}else {
//Displaying the Add button and "Item not found" ONLY IF this entity is empty (meaning barcode was not found in database)
$commands[] = ajax_command_replace($selector, "<div id = 'after_div'>Item not found.</div>");
$commands[] = ajax_command_replace("#after_status", "<div id='after_status'><button id = 'add' type = 'submit' name = 'Add' value = 'Add'>Add new item</button></div>");
}
return array('#type' => 'ajax', '#commands' => $commands);
}//end _ibbr_inv_after_callback
Ja, ich habe das getan, aber es funktioniert nicht ... Ich habe es in meinem Ajax-Befehl ersetzen, aber es funktioniert nicht. Ich weiß nicht, wo ich es einfügen soll, damit es nach "Item not found" scrollt - was übrigens auch eine ID von after_div –
@ Y.Ben hat, schau dir Edit # 2 in meiner Antwort an. –
Oh, ich sehe, was Sie getan haben, denn da wir diesen neuen JS-Code hinzufügen mussten, mussten Sie eine neue Variable erstellen und diese stattdessen als Parameter übergeben! Duh. Danke Jose !! –