EasyUI Forum

General Category => General Discussion => Topic started by: SteveG on August 10, 2016, 03:15:44 AM



Title: Problem writing value into password textbox
Post by: SteveG on August 10, 2016, 03:15:44 AM
Hi

I'm writing a bit of an application (MVC, VS2015).

Basically I have a password field and a javascript function that creates a random password and I want to update the password textbox on the page.  Simple right! - I cannot get this working for love nor money. 

The part of my View

Code:
<div class="form-group">
            @Html.LabelFor(model => model.confirmWord, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <input type="button" class="easyui-linkbutton" id="confirmwordy" onclick="updateText(this.id)" style="width:20px;visibility:hidden" value="." />
                @Html.EditorFor(model => model.confirmWord, new { htmlAttributes = new { @class = "easyui-textbox", style = "width: 300px;", id="cwordx"} })
                <img src="~/Images/Ribbon.png" onclick="writePassword()" alt="Copy password to clipboard" />
                @Html.ValidationMessageFor(model => model.confirmWord, "", new { @class = "text-danger" })
            </div>
        </div>


And I am trying to update the field with Javascript/Jquery

Code:
var ddd = generatePassword();
            alert(ddd);
            $('#cwordx').val(ddd);

Some test code I wrote trying to get to the bottom of this.

Code:
    function writePassword()
    {
        alert('1');
        var t = $('#cwordx');
        alert('2');
        t.textbox('setValue', 'hellox');
        //t.passwordbox('setText', 'hello world');
        alert('XXX');
        t.textbox('setText', 'hellox');
        alert('yyy');
    }


I was at this all day a couple of weeks ago, I tried all sorts of things to get this working - unsuccessfully.  It has taken me a couple of weeks to get access to this forum just to ask this question so I can't remember every other thing I tried, but I worked my way through the majority of the stuff from Google searches etc.  As far as I can tell the code I am using should work.  Nothing is appearing into the textbox however. 

(Ignore the hidden button on the view, it is just there for padding at the moment)

Can anyone see where I am going wrong ?

Thanks

Steve.


Title: Re: Problem writing value into password textbox
Post by: stworthy on August 10, 2016, 08:06:38 AM
To update the textbox value, you should call t.textbox('setValue', 'new value'). To update the passwordbox value, you should call t.passwordbox('setValue', 'new value').

To initialize the value when creating the field, you need to set the 'value' attribute.
Code:
<input id="pb" class="easyui-passwordbox" value="pwd" style="width:300px">


Title: Re: Problem writing value into password textbox
Post by: SteveG on August 20, 2016, 09:15:14 AM
Hi

Thanks for the response.  Unfortunately I still cannot get this to work.  Been at this nearly 2 days now :(

Nothing I try will work.  And I have tried a lot.  This is where I am at the moment.

Code:
        <div class="form-group">
            @Html.LabelFor(model => model.confirmWord, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <input type="button" class="easyui-linkbutton" id="confirmwordy" onclick="updateText(this.id)" style="width:20px;visibility:hidden" value="." />
                @Html.EditorFor(model => model.confirmWord, new { htmlAttributes = new { @class = "easyui-passwordbox", style = "width: 300px;", id= "confirmWord" } })
                @Html.ValidationMessageFor(model => model.confirmWord, "", new { @class = "text-danger" })
                <img src="~/Images/Ribbon.png" onclick="generatePassword('confirmWord')" alt="confirmy" />
            </div>
        </div>

The source of which is

Code:
<div class="form-group">
            <label class="control-label col-md-2" for="confirmWord">Confirm Password</label>
            <div class="col-md-10">
                <input type="button" class="easyui-linkbutton" id="confirmwordy" onclick="updateText(this.id)" style="width:20px;visibility:hidden" value="." />
                <input class="easyui-passwordbox text-box single-line password" data-val="true" data-val-equalto="The password and confirmation do not match." data-val-equalto-other="*.word" id="confirmWord" name="confirmWord" style="width: 300px;" type="password" value="" />
                <span class="field-validation-valid text-danger" data-valmsg-for="confirmWord" data-valmsg-replace="true"></span>
                <img src="/Images/Ribbon.png" onclick="generatePassword('confirmWord')" alt="confirmy" />
            </div>
        </div>

and the Javascript I am using to update the password box is

Code:
    function generatePassword(idx)
    {
        var newPass = Math.random().toString(36).substr(2, 9);
        alert(newPass);

        var t = $('#confirmWord');

        alert('interim');
       
        t.passwordbox('setValue', 'new value');

        alert('here!');
    }

I see the 'interim' alert box but nothing else.  I've abandoned the parameter for the time being and hard coded the reference in to try and keep things simple.  As is the none use of the hard coded 'new value' rather than newPass.

There looks to be something going wrong with
Code:
t.passwordbox('setValue', 'new value');

as I get the 'interim' but never the 'here!'.

Can someone see where I am going wrong.  I thought this would be a 15 min job to sort (and it should be!) where as now I'm around the 15 hours mark :/

I cannot for the life of me see where I am going wrong.  I've tried nearly everything I can think of.

When I saw the last response I thought the problem I was having was that I was still using the

@class = "easyui-textbox"

rather than the

@class="easyui-passwordbox"

neither will allow me to update the text.  I have never seen the final alert message in the generatePassword function.

Any help here would be greatly appreciated!

I'm absolutely stumped.

Thanks

Steve.


Title: Re: Problem writing value into password textbox
Post by: stworthy on August 20, 2016, 05:36:21 PM
Please look at this example http://code.reloado.com/amewuh/edit#preview. It works fine.


Title: Re: Problem writing value into password textbox
Post by: SteveG on August 21, 2016, 01:19:45 AM
Finally!  Thanks mate, I owe you one.

Not sure of the exact reason as yet but it looks like I might have been using an older version.  I replaced the

<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/jquery.easyui-1.4.5.min.js"></script>

lines in my code to

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>

and everything is now working as intended.  Two days pulling my hair out with that...  Thanks again mate :)

Steve.