示例#1
0
    function javascriptValidation($stepNum)
    {
        ?>
    <script type="text/javascript">

      function validateForm() {
        var errors = 0;
        var elements = $("#step-" + <?php 
        echo $stepNum;
        ?>
).find(':input');
			  elements.each(function() {
		  		if ($(this).is("input:text")) {
		  		  var container = $(this).parent().parent();
					  if ($(this).val() == "") {
						  container.addClass("error");
						  $(this).siblings().show();
						  errors++;
					  } else if ($(this).val() != "" && $(this).parent().parent().hasClass("error")) {
						  container.removeClass("error");
						  container.find('.error-msg').hide();
						  //$(this).siblings().hide();
					  }
				  }
			  });

			  var invalidBitcoinAddr = false;
				$.ajax({
					url: '<?php 
        echo Routes\validAddress();
        ?>
' + $("#widget-bitcoin-address").val(),
					type: 'get',
					dataType: 'text',
					async: false,
					success: function(data) {
						if (data != 'true') invalidBitcoinAddr = true;
					}
				});
			  if (invalidBitcoinAddr) {
					$("#bitcoin-addr-control-group").addClass("error");
					$("#bitcoin-addr-control-group .not-error").hide();
					$("#bitcoin-addr-control-group .error-msg").show();
					return false;
			  }

			  var amountToRaise = $("#widget-want-to-raise").val();
			  if (!isNumber(amountToRaise)) {
			  	$("#widget-goal").addClass("error");
			  	$("#widget-goal .error-msg").show();
			  	errors++;
			  }

			  if (errors > 0) return false; else return true;
      }
      
      function isNumber(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
      }

    </script>
  <?php 
    }
 /**
  * Previously, a NetworkError exception would reach the top level if Blockchain.info were
  * down; instead, the validate-address action should at least not lead to an exception.
  */
 function testAddressValidationGracefullyHandlesProblemAtBlockchainDotInfo()
 {
     $this->get(Routes\validAddress('1TestForDowntimeX1iTDhViXbrogKqzbt'));
 }