Я никогда не использовал SimpleModal, но из примеров на их сайте видно, что вы можете установить контейнер CSS. Если вы хотите, чтобы высота регулировалась, попробуйте установить высоту auto
$("#sample").modal({
containerCss:{
backgroundColor:"#fff",
borderColor:"#0063dc",
height:450,
padding:0,
width:830
}
});
Хотя в примере его нет, я думаю, вам нужно добавить px
после высоты и ширины в кавычках (например, "450px"
).
Хорошо, вот еще одна идея. Возможно, это слишком много, но добавьте скрытое поле ввода:
<div id="myDiv">
<form ...>
Enter your name: <input id="txtYourName" type="text" name="YourName" value="" />
<span id="errorYourName"></span>
<input type="submit" ... />
<input id="updated" type="hidden" />
</form>
</div>
затем прикрепите событие изменения, которое срабатывает одновременно с обновлением сообщения об ошибке.
$(document).ready(function() {
$("#txtYourName").live("blur", function() {
if (validateInput($("#txtYourName").val())) {
$("#errorYourName").html("");
// entry 1
} else {
// entry 2
$("#errorYourName").html("This name is not valid.");
$("#updated").trigger('change');
}
});
$("#updated").change(function(){
// resize the modal window & reposition it
})
});
Это не проверено и может быть за бортом, но я не вижу функции обновления в SimpleModal.
Обновление : Извините, я понял, что размытие не поддерживается живым событием. Поэтому я провел дополнительное тестирование и подготовил рабочую демонстрацию. Я разместил это в этом pastebin (не обращайте внимания на включенный код SimpleModal внизу). Вот необходимый код
CSS
#myDiv { line-Height: 25px; }
#simplemodal-container { background-color:#444; border:8px solid #777; padding: 12px; }
.simplemodal-wrap { overflow: hidden !important; }
.error { color: #f00; display: none; }
input { float: right; }
HTML
<div id="myDiv">
<form>
What is your name: <input id="txtYourName" type="text" name="YourName" value="" /><br>
<div id="errorYourName" class="error">This name isn't Arthur.</div>
What is your quest: <input id="txtYourQuest" type="text" name="YourQuest" value="" /><br>
<div id="errorYourQuest" class="error">This quest must be for the Grail.</div>
What is your favorite color: <input id="txtYourColor" type="text" name="YourColor" value="" /><br>
<div id="errorYourColor" class="error">Sorry, you must like red or blue.</div>
What is the air speed velocity of an unladen swallow:<br>
Type:
<select>
<option>African</option>
<option>European</option>
</select>
<input id="txtYourGuess" type="text" name="YourGuess" value="" /><br>
<div id="errorYourGuess" class="error">This guess stinks.</div>
<hr>
<input id="submitMe" type="submit" />
</form>
</div>
Сценарий
$(document).ready(function(){
$("#myDiv").modal({
containerCss:{
height: '165px',
width: '350px'
}
})
$("#txtYourName").focus();
addValidate('#txtYourName','Arthur','#errorYourName');
addValidate('#txtYourQuest','Grail|grail','#errorYourQuest');
addValidate('#txtYourColor','red|blue','#errorYourColor');
addValidate('#txtYourGuess','11|24','#errorYourGuess'); // See http://www.style.org/unladenswallow/ ;)
$("#myDiv form").change(function() {
// This is called if there are any changes to the form... added here for an example
// alert('Form change detected');
});
})
function addValidate(el,valid,err){
$(el).blur(function() {
if ( $(el).val().length > 0 && !$(el).val().match(valid) ) {
if ($(err).is(':hidden')) {
$('#simplemodal-container').animate({'height': ($('#simplemodal-container').height() + 25) + 'px'},1000);
$(err).slideDown(1000);
}
} else {
// entry 2
if ($(err).is(':visible')) {
$('#simplemodal-container').animate({'height': ($('#simplemodal-container').height() - 25) + 'px'},1000);
$(err).slideUp(1000);
}
}
});
}