mercredi 6 mai 2015

Pass the triggered element to the bootbox callback jquery

I want to pass the 'a.delete' triggered element to my bootbox callback, is there a way to do that?

var confirm = false;
$('body').on('click', 'a.delete', function(e) {
    if( confirm == false){ e.preventDefault(); }
    bootbox.confirm("Confirm?", function(result) {
        if(result == true){
            confirm = true;
            $(this).trigger('click');
        }
    });
});

EDIT Well, Taplar I did what you said, but isn't triggering the action, even if the "trigger click" is working...

var confirm = false;
$('body').on('click', 'a.delete', function(e) {
    var element = $(this);
    if( confirm == false){
        e.preventDefault();
        bootbox.confirm("Confirm?", function(result) {
            if(result == true){
                confirm = true;
                console.log(confirm);
                element.trigger('click');
            }
        });
    } else {
        console.log('triggered again');
    }
});

EXIT: What I get after clicking the confirm button

true

triggered again

My Solution

var confirm = false;
$('body').on('click', 'a.delete', function(e) {
    var element = $(this);
    if( confirm == false){
        e.preventDefault();
        bootbox.confirm("Confirm?", function(result) {
            if(result == true){
                confirm = true;
                $(element)[0].click();
            }
        });
    } else {confirm = false;}
});

JQuery validation message appearing weirdly between two radio buttons

I am using JQuery Validation plugin to validate my form. The validation messages for all the fields except radio button are showing properly below the respective field.But for radio button the messages are showing between first two radio buttons.

gender : {
    required : true
    }


<html:radio property="gender" value="1"
        name="formBean" styleId="gender">&nbsp;Male&nbsp;</html:radio>
    <html:radio property="gender" value="0"
        name="formBean" styleId="gender">&nbsp;Female&nbsp;</html:radio>

enter image description here

Is there any way the error message shown after or below the radio buttons?

Thanks in advance.

Why Can't I get my google maps to update lat/lng on button click?

I am trying to get my center location to change on my google map based on a button click. I have more functionality to add later, but I can't get this basic update to work. I have a default value that loads on page load. The button should set a new location, but I see that it does update but then is quickly overridden by the default value because the page loads again.

I am new to google maps, and I am just trying to figure out how to load and interact with the map correctly.

Here is my code:

         <script src="http://ift.tt/13qgtmt"></script>                                                        
<script>

    var deanLat = 43.0843816;
    var deanLong = -89.5302394;
    var deanAddress = '1277 deming way, madison wi';

    var stmaryLat = 43.0592730;
    var stmaryLong = -89.4015130;
    var stmaryAddress = '700 S Park St, Madison, WI 53715';

    $("#FindDean").click(function() {
       refreshMap(deanLat, deanLong);
       });

    function alertme(message) {
          alert (message);
      }


    function refreshMap(ilat,ilong) {
       ilat = typeof ilat !== 'undefined' ? ilat : stmaryLat;
       ilong = typeof ilong !== 'undefined' ? ilong : stmaryLong;
        alertme(ilat);
        var mapOptions = {  
                zoom: 16,
                center: new google.maps.LatLng(ilat, ilong)
            };

        gmap = new google.maps.Map(document.getElementById('mapholder'),
          mapOptions);
    }


    function loadScript() {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = 'http://ift.tt/1lrRXYd' +
          '&signed_in=true&callback=refreshMap';
      document.body.appendChild(script);
    }
   window.onload = loadScript;

Submitting Values From a Jquery Slider

Hey guys I have this code here for a jquery slider. I want to take the value of the slider out and use an http post method to submit the value to a database. I have a processing form which I used successfully for textboxes and radio buttons. I was hoping to save the value of the slider in a hidden field and just post it. I know this gets the value from the slider.

    var selection = $( ".selector" ).slider( "value" );

Now how can I add this into the value in this submit form?

    <input type='hidden' class="mainForm" id="fieldBox_5" name="field_5" value=selection>

This is my whole code.

    <<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Slider - Slider bound to select</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="style.css">
  <script>
  $(function() {
    var select = $( "#minbeds" );
    var slider = $( "<div id='slider'></div>" ).insertAfter( select ).slider({
      min: 1,
      max: 10,
      range: "min",
      value: select[ 0 ].selectedIndex + 1,
      slide: function( event, ui ) {
        select[ 0 ].selectedIndex = ui.value - 1;
      }
    });
    $( "#minbeds" ).change(function() {
      slider.slider( "value", this.selectedIndex + 1 );
    });
  });
  var selection = $( ".selector" ).slider( "value" );
  </script>
</head>
<body>

<form id="mainForm_1" class="MainForm" method=post enctype=multipart/form-data action=processorss.php onSubmit="return validatePage1();">



  <label for="minbeds" class="mainForm">Rate Your Prefence for Fish 1-10</label>
 <select name="minbeds" id="minbeds">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
  </select>
  <li class="mainForm">



  <input type='hidden' class="mainForm" id="fieldBox_5" name="field_5" value=selection>

                    <input id="saveForm" class="mainForm" type="submit" value="Submit" />
                </li>
</form>


</body>
</html>

FullCalendar Horizontal Time Range Selection

Can someone tell me how to achieve something like below image. How can I select particular time range in selected days.

Notice that the selection spans multiple days. It's a horizontal selection across multiple days (as opposed to a continuous one).

I am using fullCalendar jquery library.

intended result

jQuery - Ask for width or height in percent % and returns me in 0 pixels

I've set styles in % like:

<style>
#somediv {width:70%}
</style>
<div id="#somediv"></div>

And it returns me the result in pixels with jQuerys css() function

$(document).ready(function(){
var css = $("#somediv").css('width');
console.log(css);
})

Argument is null in call to .NET Web API GET method

I have two similar Web API controllers, one working and one not. Can't find why the broken one is not working. What happens is all the fields of the input argument are null. Here's the controller method signature:

public IEnumerable<Product> GetProducts([FromUri] StateQuery query)

Parameter type:

public class StateQuery
{
    public State state;
    public string username;
    public string password;
}

Routing:

config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
            name: "Default",
            routeTemplate: "api/{controller}/{action}"
);

Calling the endpoint:

var uri = 'api/product/';
var query = {
                username: $("#user").val(),
                password: $("#password").val(),
                state: { "name": $("#state").val(), "Counties": [{ "Name": $("#county").val() }] }
            };


$.getJSON(uri + 'getProducts', query)
              .done(function (data) {
                  $('#product').text(data);
                  console.log(data);
              })
              .fail(function (jqXHR, textStatus, err) {
                  $('#product').text('Error: ' + err);
              });

I've tried attribute routing, tried calling from the browser address bar, tried simplifying the input to just username and password, no change. All the fields of query are always null. I also tried changing it to return a IHttpActionResult, which is the main difference between this and the working controller (other than what it does of course) but that had no effect. The method is getting called, so the routing is working, but there is something wrong with the argument binding that I'm just not seeing.

Does anybody see the problem or just a direction to look? I've spent all morning reading tutorials and SO questions and everything I'm seeing indicates that I'm on the right track. Maybe there's some little thing I'm missing because I've been staring at it too long.