Azkarra eta erraza: Erabili jQuery Testu Eremuaren bat ezkutatzeko SharePoint formularioa batean

Hau nire post bat da serie-on going nola erabili jQuery SharePoint batera.
Nahi duzun jQuery buruz gehiago jakin nahi baduzu, Gomendatzen dut oso: Ekintza jQuery Bear Bibeault eta Yehuda Katz arabera.

UPDATE (dagoeneko!): Modu bat hobeto kokatu nahi nuen uste <TR> tag I want to hide and wrote about it here. You may still find this article interesting anyway so I’m leavnig it up.

I want to hide a text field, “Hide Me!” as shown:

image

The following jQuery does the trick for me:

<script mota ="text/javascript">

  $(funtzioa() {


    $('Sarrera[title = Ezkutatu Me!]').gurasoa().gurasoa().gurasoa().ezkutatu();

  });

</script>

The code is saying, “find me all input fields whose title = Hide Me!. Gero, get its parent and then next parent and the *next* parent (phew!) and invoke the hide() method on that thing, whatever it happens to be.

I figured out that parent structure by viewing the HTML for the form that SharePoint created as shown:

<TR>
    <TD nowrap="true" valign="top" zabalera="190px" klasean="ms-formlabel">
        <H3 klasean="ms-standardheader">
            <nobr>Hide Me!</nobr>
        </H3>
    </TD>

    <TD valign="top" klasean="ms-formbody" zabalera="400px">
        <!-- FieldName="Hide Me!"
                 FieldInternalName="Hide_x0020_Me_x0021_"
                 FieldType="SPFieldText"
        -->
        <span dir="none">
            <sarrera
                izena="ctl00$m$g_bdb23c2c_fde7_495f_8676_69714a308d8e$ctl00$ctl04$ctl02$ctl00$ctl00$ctl04$ctl00$ctl00$TextField"
                mota="text"
                maxlength="255"
                id="ctl00_m_g_bdb23c2c_fde7_495f_8676_69714a308d8e_ctl00_ctl04_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_TextField"
                izenburua="Hide Me!"
                klasean="ms-long" />
                <br>
        </span>


    </TD>
</TR>

Argazki hau bera erakusten, baina markatutako gurasoekin batera:

image

Lehen gurasoak (1) is a span tag. Span’s parent (2) TD etiketa bat da, eta, ondoren, azkenean, iritsi da benetako guraso ezkutatu nahi dut dugu (3) horrek TR Etiketa berez ez da.

This is a pretty terrible approach I think because it’s extremely dependent on the very specific structure of this form. When SharePoint 2010 ateratzen, this whole structure could change and break this approach. What I really want to do is craft a jQuery selector that is along the lines of “find me all the TR’s (and only TR tags) that have somewhere in their child elements an input field whose title = Hide Me!". I starting from the bottom and moving up. Assuming I figure this out, I’ll post an updated “quick and easy’ post.

</amaiera>

Nire blog Harpidetu.

Follow me on Twitter http://www.twitter.com/pagalvin

Pentsatu zen "Azkarra eta erraza: Erabili jQuery Testu Eremuaren bat ezkutatzeko SharePoint formularioa batean

  1. Jaap Vossers

    what about this approach for finding the parent tr? First node in the collection of ancestor nodes that are tr elements, resulting in the closest parent tr.

    .parents("tr:first")

    Erantzun

Utzi iruzkin bat

Zure e-posta helbidea ez da argitaratuko. Beharrezko eremuak markatu dira *