Unable to postBack from sheet

  1. 5 years ago

    @Toby I am having difficulties showing a sheet and posting back formData. This is what I have so far.

    js file:

    $(function() {
    	$("#addWarning").live("click", function(e) {
    		e.preventDefault();
    		loadWarningSheet();
    	});
    });
    
    
    function loadWarningSheet(formData) {
    		ETSheet.loadSheet("warningSheet", "conversation/warning.view/"+$(this).parents(".post").data("id"), function() {
    
    			$(this).find("form").ajaxForm(
    	            "submit", // The name of the button that should be "clicked" when this form is submitted
    	            loadWarningSheet // Callback to pass form data to
    	        );
    
    		}, formData);
    
    }

    sheet file:

    <?php
    // Copyright 2011 Toby Zerner, Simon Zerner
    // This file is part of esoTalk. Please see the included license file for usage information.
    
    if (!defined("IN_ESOTALK")) exit;
    $form = $data["form"];
    //echo $form->open();
    ?>
    <div class='sheet' id='warningSheet'>
    <div class='sheetContent'>
    
    <h3><?php echo T("Add a converstation warning"); ?></h3>
    
    <?php
    echo $form->input("description", "textarea", array("cols" => 20, "rows" => 5));
    echo $form->button("save", "Submit Form");
    echo $form->close();
    ?>
    </div>
    </div>

    plugin.php

    	public function conversationController_warning($sender, $data, $postId = false)
    	{
    		//if (!($postId = (int)$postId)) return;
    		$post = ET::postModel()->getById($postId);
    		//if (!$post) return;
    
    		//$sender->data("members", $post["warning"]);
    		$form = ETFactory::make("form");
    		$form->action = URL("conversation/save");
    
    		if ($form->validPostBack("save")) {
    			//data..
    		}
    
    		$sender->data("form", $form);
    		$sender->render($this->getView("warning"));
    	}

    Now when I uncomment echo $form->open(); the hole sheet wont load. And I am not sure how to dismiss the sheet on submit. The recent written documentation helps me a fair bit but I am stuck here.

  2. Toby

    16 Apr 2014 Administrator

    Uncomment echo $form->open(); and move it inside of <div class="sheetContent">.

  3. @Toby Uncomment echo $form->open(); and move it inside of <div class="sheetContent">.

    Thanks, now do I need to unload the sheet on save by JavaScript again?

  4. Toby

    17 Apr 2014 Administrator

    Yep. If the save is successful, do ETSheet.hideSheet("warningSheet")

  5. Edited 5 years ago by Tristan

    @Toby Yep. If the save is successful, do ETSheet.hideSheet("warningSheet")

    Can you explain some more? I am not getting the sheet to close. It closes but pops back up right after.
    [edit]
    The only way to get it work is like this, but I don't think it is a neat solution.

    function loadWarningSheet(formData) {
    	if (!formData) {
    		ETSheet.loadSheet("warningSheet", "conversation/warning.view/"+$(this).parents(".post").data("id"), function() {
    
    		$(this).find("form").ajaxForm(
    	        "submit",
    	        loadWarningSheet
    	    );
    
    		}, formData);
    	}
    	else  {
    		console.log(formData)
    		ETSheet.hideSheet("warningSheet");
    	}
    }
  6. Toby

    24 Apr 2014 Administrator

    Ah, so this is actually a bit tricky and wasn't possible to do correctly with ETSheet.loadSheet — it required manually loading a view with an AJAX call and then calling ETSheet.showSheet with its response.

    However, I've just committed fcba641 to make it easier; the sheet will automatically be hidden if the AJAX request returns no view. So, in the controller, just don't render the sheet if the save is successful. (Untested, let me know if you have problems!)

  7. Thank, I'll give it a try and let you know. Can you update the docs accordingly?

  8. Toby

    24 Apr 2014 Administrator

    Already done, just haven't pushed it yet :)

  9. Cool, thanks!

 

or Sign Up to reply!